public Vector2 GetJumpNormalVelocity(Direction2H wallSlideDirection, float moveInput)
    {
        Vector2     jumpNormalVelocity;
        bool        isBetweenWalls     = wallSlideRaycaster.IsBetweenWalls();
        Direction2H moveInputDirection = Direction2HHelpers.FromFloat(moveInput);

        if (moveInput == 0)
        {
            jumpNormalVelocity = jumpOffNormalVelocity;
        }
        else if (wallSlideRaycaster.IsTouchingWall(moveInputDirection) || isBetweenWalls)
        {
            jumpNormalVelocity = wallClimbNormalVelocity;
        }
        else
        {
            jumpNormalVelocity = wallLeapNormalVelocity;
        }
        float wallSlideXSign = 0;

        if (!isBetweenWalls)
        {
            wallSlideXSign = wallSlideDirection.ToFloat() * -1;
        }
        Vector2 oppositeToWallVector = new Vector2(wallSlideXSign, 1);

        return(jumpNormalVelocity * oppositeToWallVector);
    }
示例#2
0
 public void StartState()
 {
     controller.animator.PlayFly();
     elapsedTime               = 0;
     isTrackingPlayer          = true;
     flyDirection              = GetDirectionToTarget();
     controller.flip.Direction = Direction2HHelpers.FromFloat(flyDirection.x);
 }
    private Bt WalkUpdate()
    {
        Vector2     distance      = goBackPosition - (Vector2)transform.position;
        float       distanceX     = distance.x;
        Direction2H moveDirection = Direction2HHelpers.FromFloat(distanceX);

        physics.WalkInDirection(moveDirection);
        return(Bt.Running);
    }
示例#4
0
 public void UpdateState()
 {
     if (isTrackingPlayer)
     {
         if (IsTargetDead())
         {
             isTrackingPlayer = false;
         }
         else if (elapsedTime < trackPlayerTime)
         {
             flyDirection = GetDirectionToTarget();
             controller.flip.Direction = Direction2HHelpers.FromFloat(flyDirection.x);
         }
     }
     else if (elapsedTime >= destroyAfterFlyTime)
     {
         controller.destroyable.DestroyEnemy();
     }
     controller.physics.FlyToTarget(flyDirection);
     elapsedTime += Time.deltaTime;
 }
示例#5
0
    public void ControlUpdate()
    {
        float movementInput = input.movement.Value;

        if (physics.IsGrounded)
        {
            if (!wasGrounded)
            {
                smoothDampAccelerateVelocity = 0;
                smoothDampDecelerateVelocity = 0;
                wasGrounded = true;
            }
            velocity = GetVelocity(movementInput, groundedMovement);
        }
        else
        {
            if (wasGrounded)
            {
                smoothDampAccelerateVelocity = 0;
                smoothDampDecelerateVelocity = 0;
                wasGrounded = false;
            }
            velocity = GetVelocity(movementInput, aerialMovement);
        }
        physics.velocity.X = velocity;
        physics.walkState  = PlayerWalkStateHelpers.FromFloat(movementInput);
        if (movementInput != 0)
        {
            flip.Direction = Direction2HHelpers.FromFloat(movementInput);

            if (!audioSource.isPlaying && physics.IsGrounded)
            {
                audioSource.Play();
            }
        }
        else if (audioSource.isPlaying)
        {
            audioSource.Stop();
        }
    }
示例#6
0
    public void WallSlideUpdate()
    {
        wallSlideRaycaster.CheckWallCollision();
        float moveInput = input.movement.Value;

        if (input.jump.IsPressed())
        {
            input.jump.Use();
            jump.PerformJump(wallSlideDirection.Value, moveInput);
            stateMachine.SetControlState();
            wallSlideDirection = null;
            unstickTimeLeft    = 0;
            return;
        }
        else
        {
            bool        noMoveInput        = moveInput == 0;
            Direction2H moveInputDirection = Direction2HHelpers.FromFloat(moveInput);

            if (noMoveInput)
            {
                unstickTimeLeft = noInputUnstickTime;
                stateMachine.SetControlState();
                return;
            }
            else if (!wallSlideRaycaster.IsTouchingWall(wallSlideDirection.Value))
            {
                unstickTimeLeft = oppositeInputUnstickTime;
                stateMachine.SetControlState();
                return;
            }
            else if (wallSlideDirection != moveInputDirection)
            {
                unstickTimeLeft = oppositeInputUnstickTime;
                stateMachine.SetControlState();
                return;
            }
        }
    }
示例#7
0
    public void ControlUpdate()
    {
        if (!wallSlideEnabled)
        {
            return;
        }

        wallSlideRaycaster.CheckWallCollision();
        float       moveInput          = input.movement.Value;
        Direction2H moveInputDirection = Direction2HHelpers.FromFloat(moveInput);
        bool        isFalling          = !physics.IsGrounded && physics.velocity.Y < 0;
        bool        isTouchingAnyWall  = wallSlideRaycaster.IsTouchingAnyWall();
        bool        isOrWasWallSliding = isTouchingAnyWall || unstickTimeLeft > 0;

        if (isFalling && isOrWasWallSliding && input.jump.IsPressed())
        {
            input.jump.Use();
            Direction2H wallSlideDirectionForJump = GetWallSlideDirectionForJump();
            jump.PerformJump(wallSlideDirectionForJump, moveInput);
            wallSlideDirection = null;
            unstickTimeLeft    = 0;
            return;
        }
        else if (isFalling && moveInput != 0 && wallSlideRaycaster.IsTouchingWall(moveInputDirection))
        {
            wallSlideDirection = moveInputDirection;
            stateMachine.SetWallSlideState();
        }

        if (unstickTimeLeft > 0)
        {
            unstickTimeLeft -= Time.deltaTime;
            if (unstickTimeLeft <= 0)
            {
                wallSlideDirection = null;
            }
        }
    }
示例#8
0
    internal void SetTarget(PlayerUnitController unitToFollow)
    {
        Vector2 distance = unitToFollow.transform.position - transform.position;

        moveDirection = Direction2HHelpers.FromFloat(distance.x);
    }
 public void SetLaunchVelocity(Vector2 launchVelocity)
 {
     physics.velocity.Value = launchVelocity;
     yeetTimeLeft           = yeetTime;
     flip.Direction         = Direction2HHelpers.FromFloat(launchVelocity.x);
 }