コード例 #1
0
        private bool ShouldJump(Pathfinder.PathfindCell targetCell)
        {
            var isBelowTarget = _owner.GlobalPosition.y - targetCell.GlobalPosition.y >= 16f;
            // this doesn't work because it can pathfind to the middle of a platform
            // in other words, the pathfinding for jumping is not only corner to corner
            var isFarHorizontal = Mathf.Abs(targetCell.GlobalPosition.x - _owner.GlobalPosition.x) > 16f * 6f;

            return((!isBelowTarget && isFarHorizontal) || isBelowTarget);
        }
コード例 #2
0
        private float GetJumpSpeed(Pathfinder.PathfindCell targetCell)
        {
            var dir     = (targetCell.GlobalPosition - _owner.GlobalPosition);
            var angle   = dir.Angle();
            var percent = 1f;

            if (angle > 0)
            {
                var halfPi = Mathf.Pi * .5f;
                percent = Mathf.Abs((1f - (angle / halfPi))) * .75f;
            }

            var length        = (targetCell.GlobalPosition - _owner.GlobalPosition).Length();
            var maxJumpHeight = (length) * percent;
            var jumpVel       = Mathf.Sqrt(2f * 800f * maxJumpHeight);

            return(jumpVel);
        }