Пример #1
0
    public override void _PhysicsProcess(float delta)
    {
        if (dragging)
        {
            //We continuesly update the start position for our force add direction to the position the blob is
            dragStartPos = GlobalPosition;
        }
        //If the dragging has not completed we just exit out of hte method
        if (!dragComplete)
        {
            return;
        }
        moveDirection = dragEndPos - dragStartPos;
        moveDirection = moveDirection.Normalized();
        ApplyCentralImpulse(moveDirection * speed);
        dragging     = false;
        dragComplete = false;

        //Bug or feature? Tis piece of code forces the red blob to stop before being able to shoot of in a direction again
        if (Mathf.Abs(LinearVelocity.x) > maxSpeed || Mathf.Abs(LinearVelocity.y) > maxSpeed)
        {
            Vector2 newSpeed = LinearVelocity.Normalized();
            newSpeed      *= maxSpeed;
            LinearVelocity = newSpeed;
        }
    }
Пример #2
0
    private void ApplyLinear(float delta)
    {
        Vector3 force    = GetLinearAction();
        Vector3 dirForce = Transform.basis.Xform(force);

        ApplyCentralImpulse(dirForce * acceleration * delta);
        Vector3 lin_vel   = LinearVelocity.Normalized();
        Vector3 remainder = lin_vel - dirForce.Normalized();

        ApplyCentralImpulse(remainder * -accelerationDampening);
    }
Пример #3
0
    private void LookFollow(PhysicsDirectBodyState state, Transform currentTransform, Vector3 targetPosition)
    {
        var myPosition = currentTransform.origin;

        var dist       = (myPosition - targetPosition).Length();
        var _targetDir = myPosition - (myPosition - targetPosition).Normalized();
        var targetDir  = currentTransform.XformInv(_targetDir);

        var forward = targetDir.Dot(new Vector3(0, 0, 1));
        var rightn  = targetDir.Dot(new Vector3(1, 0, 0));
        var upn     = targetDir.Dot(new Vector3(0, 1, 0));

        currentTransform.origin = new Vector3();
        float spiral         = dist * 0.01f;
        var   worldVelDir    = LinearVelocity.Normalized();
        var   worldTargetDir = currentTransform.Xform(targetDir);
        var   turnRate       = 30.0f;

        if (forward > 0.99f)
        {
            GetNode <Particles>("Particles").Emitting = true;
            var correction = ((worldTargetDir - worldVelDir) * 20.0f) + (Transform.basis.z * 100);
            state.ApplyCentralImpulse(correction * state.GetStep());
        }
        else
        {
            GetNode <Particles>("Particles").Emitting = false;
            spiral   = 0;
            turnRate = 5;
            var correction = (worldTargetDir - worldVelDir) * 40.0f;
            state.ApplyCentralImpulse(correction * state.GetStep());
        }
        float ss   = (float)Math.Sin(TTL * 10.0f) * spiral;
        float cs   = (float)Math.Cos(TTL * 10.0f) * spiral;
        var   turn = new Vector3(-upn + ss, rightn - cs, 0) / turnRate;

        turn = Transform.Xform(turn) - Transform.origin;
        state.SetAngularVelocity(turn / state.GetStep());
    }
Пример #4
0
    // Called every frame. 'delta' is the elapsed time since the previous frame.
    public override void _PhysicsProcess(float delta)
    {
        //If we dont have a target then return out of the method
        if (target == null)
        {
            return;
        }

        //Impliment movement here hahaha pproblem for future Gerrie? dont know yet
        Vector2 moveDir = target.Position - Position;

        moveDir = moveDir.Normalized();
        ApplyImpulse(moveDir, moveDir * speed);
        //AddForce(moveDir, moveDir * speed);

        if (Mathf.Abs(LinearVelocity.x) > maxSpeed || Mathf.Abs(LinearVelocity.y) > maxSpeed)
        {
            Vector2 newSpeed = LinearVelocity.Normalized();
            newSpeed      *= maxSpeed;
            LinearVelocity = newSpeed;
        }
    }
Пример #5
0
    public override void _PhysicsProcess(float delta)
    {
        var dir = LinearVelocity.Normalized().Angle();

        SetRotation(dir);
    }