Untitled

mail@pastecode.io avatar
unknown
csharp
a month ago
1.5 kB
6
Indexable
Never
using UnityEngine;
using UnityEngine.InputSystem;

public class MoveAction : PlayerAction
{
    // On Move

    Vector2 move;

    public void OnMove(InputAction.CallbackContext callbackContext)
    {
        move = callbackContext.ReadValue<Vector2>();
    }

    // On Enable

    void OnEnable()
    {
        playerPhysics.onPlayerPhysicsUpdate += Move;
    }

    //On Disable

    void OnDisable()
    {
        playerPhysics.onPlayerPhysicsUpdate -= Move;
    }

    //Move

    // [SerializeField] Transform cameraTransform;

    [SerializeField] float speed;
    

    void Move()
    {
        // GetMoveVector(cameraTransform, groundInfo.normal, move);

        RB.velocity = Vector3.ProjectOnPlane((Vector3.right * move.x * speed) + (Vector3.forward * move.y * speed), groundInfo.normal)
        + playerPhysics.verticalVelocity;
    }

    //Get Move Vector

    // Vector3 GetMoveVector(Transform relativeTo, Vector3 upNormal, Vector2 move)
    // {
    //     Vector3 rightNormal = Vector3.Cross(upNormal, relativeTo.forward);

    //     Vector3 forwardNormal = Vector3.Cross(relativeTo.right, upNormal);

    //     Vector3.OrthoNormalize(ref upNormal, ref forwardNormal, ref rightNormal);

    //     Debug.DrawRay(RB.transform.position, rightNormal * 10, Color.red);
    //     Debug.DrawRay(RB.transform.position, forwardNormal * 10, Color.green);

    //     return (rightNormal * move.x) + (forwardNormal * move.y);
    // }
}
Leave a Comment