Ejemplo n.º 1
0
    void Update()
    {
        float   x           = Input.GetAxis("Horizontal");
        float   z           = Input.GetAxis("Vertical");
        Vector3 flatForward = Camera.main.transform.forward;

        flatForward.y = 0.0f;
        Vector3 flatRight = Camera.main.transform.right;

        flatRight.y = 0.0f;
        Vector3 controlledMovement = flatForward.normalized * z + flatRight.normalized * x;

        System.Type t = currMovementState.GetState();
        if (t != currMovementState.GetType())
        {
            SetMovementState(t);
        }
        // TODO: remove first parameter to GetMovement and reference cc.velocity in the function
        // movement = currMovementState.GetMovement(movement, controlledMovement);
        movement = currMovementState.GetMovement(cc.velocity, controlledMovement);

        movement += Physics.gravity * Time.deltaTime;
        Vector3 frameMovement = movement * Time.deltaTime;

        cc.Move(frameMovement);

        // TODO: handle turning in movement states
        TurnTowards(controlledMovement);
    }