Esempio n. 1
0
        // Put any code in here you want to run AFTER the state's update function.
        // This is run regardless of what state you're in.
        protected override void LateGlobalSuperUpdate()
        {
            // Move the player by our velocity every frame.
            transform.position += currentVelocity * warriorController.superCharacterController.deltaTime;

            // If alive and is moving, set animator.
            if (warriorController.canMove)
            {
                if (currentVelocity.magnitude > 0 && warriorController.HasMoveInput())
                {
                    warriorController.isMoving = true;
                    warriorController.SetAnimatorBool("Moving", true);
                    warriorController.SetAnimatorFloat("Velocity", currentVelocity.magnitude);
                }
                else
                {
                    warriorController.isMoving = false;
                    warriorController.SetAnimatorBool("Moving", false);
                    warriorController.SetAnimatorFloat("Velocity", 0);
                }
            }

            RotateTowardsMovementDir();

            // Update animator with local movement values.
            warriorController.SetAnimatorFloat("Velocity", transform.InverseTransformDirection(currentVelocity).z);
        }
    public void GetNewPosition(float deltaTime, out Vector3 newPosition, out Vector3 newEulerAngles)
    {
        newPosition    = transform.position;
        newEulerAngles = transform.localEulerAngles;
        if (!isHitBack)
        {
            float x;
            float z;
            //bool jumpPressed = false;

            float scale = 10f;
            x = Input.GetAxis("Horizontal") * scale;
            z = Input.GetAxis("Vertical") * scale;
            //jumpPressed = Input.GetButtonDown("Jump");

            Vector3 screenPos      = Camera.main.WorldToScreenPoint(transform.position);
            Vector3 screenAheadPos = Camera.main.WorldToScreenPoint(transform.position + new Vector3(0f, 0f, 1f));

            Vector3 mousePos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPos.z);

            Vector3 aheadVec       = screenAheadPos - screenPos;
            Vector3 mouseObjectVec = mousePos - screenPos;

            float rotateAngle = Vector3.Angle(aheadVec, mouseObjectVec);


            if (Vector3.Dot(new Vector3(1f, 0f, screenPos.z), mouseObjectVec) >= 0f)
            {
                newEulerAngles = new Vector3(0f, rotateAngle, 0f);
            }
            else
            {
                newEulerAngles = new Vector3(0f, -rotateAngle, 0f);
            }

            Vector3 move = transform.right * x + transform.forward * z;

            //controller.Move(move * speed * Time.deltaTime);
            newPosition += move * speed * deltaTime;

            if (move.magnitude == 0)
            {
                warriorController.isMoving = false;
                warriorController.SetAnimatorBool("Moving", false);
                warriorController.SetAnimatorFloat("Velocity", 0);
            }
            else
            {
                warriorController.isMoving = true;
                warriorController.SetAnimatorBool("Moving", true);
                warriorController.SetAnimatorFloat("Velocity", (speed * move).magnitude);
            }

            ///controller.Move(velocity * Time.deltaTime);
        }
        else
        {
            if (hitBackCount >= 1)
            {
                hitBackCount--;
            }
            else
            {
                isHitBack    = false;
                hitBackCount = 25;
                hitPlayer    = this.name;
            }


            //Vector3 move = transform.forward;
            ///controller.Move(hitbackDir * backSpeed * transform.localScale.z * Time.deltaTime);
            newPosition += hitbackDir * backSpeed * transform.localScale.z * deltaTime;
        }
    }