Ejemplo n.º 1
0
    public override MovementState UpdateState(ref Vector3 velocity, ref Vector3 externalForces)
    {
        col = GetComponent<Collider2D>();

        //check to see if the tether has been thrown
        if (isThrown)
        {
            //check if temp exists, and if so, is it moving
            if (temp && !temp.Moving)
            {
                //find the angle between the player and the stopped weapon
                //then pull the player continuously towards the tether
                Vector2 pullDirection = temp.transform.position - player.transform.position;
                velocity = pullDirection * tetherForce;

                //check for collisions in the x  and y directions that the player is moving
                if ((controller.collisions.Left && direction.x < 0) || (controller.collisions.Right && direction.x > 0))
                {
                    velocity.x = 0;
                }
                if ((controller.collisions.Above && direction.y > 0) || (controller.collisions.Below && direction.x < 0))
                {
                    velocity.y = 0;
                }

                DecayExternalForces(ref externalForces);
                controller.Move(velocity * Time.deltaTime + externalForces * Time.deltaTime);
            }
            //If no on existing, exit the state
            if (!temp)
            {
                return checkState();
            }

            //otherwise update the state as it would if the tether wasn't thrown
            else
            {
                currentState = checkState();
                currentState = currentState.UpdateState(ref velocity, ref externalForces);
            }
        }
        //if not thrown, exit state
        else
        {
            return checkState();
        }

        timeLeft -= Time.deltaTime;
        return null;
    }