Пример #1
0
    private void handleStrafing(float delta)
    {
        Vector3 desiredMoveXY = new Vector3();
        Vector3 desiredMoveZ  = new Vector3();

        //Add all the WASD controls to get a vector.


        if (Claims.IsActionPressed("MoveForward"))
        {
            desiredMoveXY += Vector3.Forward;
        }
        if (Claims.IsActionPressed("MoveLeft"))
        {
            desiredMoveXY += Vector3.Left;
        }
        if (Claims.IsActionPressed("MoveBack"))
        {
            desiredMoveXY += Vector3.Back;
        }
        if (Claims.IsActionPressed("MoveRight"))
        {
            desiredMoveXY += Vector3.Right;
        }
        if (Claims.IsActionPressed("MoveUp"))
        {
            desiredMoveZ += Vector3.Up;
        }
        if (Claims.IsActionPressed("MoveDown"))
        {
            desiredMoveZ += Vector3.Down;
        }


        //what's the behavior of Normalized() when desiredMove is zero?
        //I guess it's still zero?
        var desiredMove = (desiredMoveXY + desiredMoveZ).Normalized() * maxSpeed;
        //desiredMove is still in local space.
        //We want to convert it to global space.
        Vector3 globalMove = LookPitch.GlobalTransform.basis.Xform(desiredMove);

        Translation += globalMove * delta;
        //We just apply movement manually since spectator cam doesn't have any interactions.
    }
Пример #2
0
    private void handleStrafing()
    {
        Vector3 desiredMove = new Vector3();

        //Add all the WASD controls to get a vector.

        if (Claims.IsActionPressed("MoveForward"))
        {
            desiredMove += Vector3.Forward;
        }
        if (Claims.IsActionPressed("MoveLeft"))
        {
            desiredMove += Vector3.Left;
        }
        if (Claims.IsActionPressed("MoveBack"))
        {
            desiredMove += Vector3.Back;
        }
        if (Claims.IsActionPressed("MoveRight"))
        {
            desiredMove += Vector3.Right;
        }

        //what's the behavior of Normalized() when desiredMove is zero?
        //I guess it's still zero?
        desiredMove = desiredMove.Normalized() * provider.maxSpeed;
        //desiredMove is still in local space.
        //We want to convert it to global space.
        Vector3 globalMove         = LookYaw.GlobalTransform.basis.Xform(desiredMove);
        Vector3 horizontalVelocity = LinearVelocity;

        horizontalVelocity.y = 0;

        //If we're not on the ground, reduce our control authority.
        float authority = groundCounter == 0 ? provider.acceleration / 10 : provider.acceleration;

        AddCentralForce((globalMove - horizontalVelocity) * authority);
    }