Ejemplo n.º 1
0
        public void Move(float delta, Vector3 horizontalHeading, bool isJumping, bool isSneaking, bool airJumpAllowed)
        {
            // TODO: Add acceleration curves; integrate positions to avoid FPS based de-syncs
            horizontalHeading.y = 0;
            var velocityHorizontal = Velocity.MoveToward(
                horizontalHeading.Normalized() * (isSneaking ? SneakSpeed : FullSpeed),
                FullSpeed / (Body.IsOnFloor() ? AccelTimeGround : AccelTimeAir) * delta);

            Velocity.x = velocityHorizontal.x;
            Velocity.z = velocityHorizontal.z;

            Velocity.y -= Gravity * delta;
            Velocity    = Body.MoveAndSlide(Velocity, Vector3.Up);

            // ReSharper disable once InvertIf
            if (Body.IsOnFloor())
            {
                Velocity.y = 0;
            }

            if ((Body.IsOnFloor() || airJumpAllowed) && isJumping)
            {
                Velocity.y = JumpMagnitude;
            }
        }
Ejemplo n.º 2
0
    public void PhysicsMove(float delta, ref Vector3 velocity, Vector2 moveVec, Basis moveBasis, bool sprinting = false, bool jump = false)
    {
        var moveVelocity = Vector3.Zero;

        moveVelocity  += moveBasis.x.Normalized() * moveVec.x;
        moveVelocity  += moveBasis.z.Normalized() * moveVec.y;
        moveVelocity.y = 0;
        moveVelocity   = moveVelocity.Normalized() * (sprinting ? SPRINT_SPEED : MOVE_SPEED);

        var hVelocity = velocity;

        hVelocity.y = 0;
        var accel = (moveVelocity.Dot(hVelocity) > 0) ? (body.IsOnWall() ? ACCELERATION_WALL : ACCELERATION) : DECELERATION;

        hVelocity = hVelocity.LinearInterpolate(moveVelocity, accel * delta);

        if (body.IsOnFloor() && jump)
        {
            velocity.y = JUMP_SPEED;
        }

        velocity.y += GRAVITY * delta;
        velocity.x  = hVelocity.x;
        velocity.z  = hVelocity.z;
        velocity    = body.MoveAndSlide(velocity, Vector3.Up, 0.05f, 4, Mathf.Deg2Rad(20));
    }
Ejemplo n.º 3
0
    private void Jump(object[] args)
    {
        float magnitude = (float)args[0];

        if (body.IsOnFloor())
        {
            tojump        = true;
            jumpMagnitude = magnitude;
        }
    }
Ejemplo n.º 4
0
 public override bool GetBoolValue()
 {
     if (target != null)
     {
         return(target.IsOnFloor());
     }
     else
     {
         return(false);
     }
 }