How would i go about getting and preserving the player's local y velocity, i am making a game where you can walk on a planet (player is a child of the planet), currently the movement works fine but when i walk to the side of the planet the physics start to act weird (eg. player starts to fall diagonally, player jumps diagonally from the pov of the player), i want to preserve the player's y velocity but somehow in local space? how do i do this?
movement method:
Vector3 moveDir = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical")).normalized;
Vector3 targetMoveAmount = moveDir * walkSpeed;
moveAmount = Vector3.Lerp(moveAmount, targetMoveAmount, Time.deltaTime * 8);
private void Movement()
{
float currentYVelocity = rb.velocity.y;
Vector3 newVelocity = orientation.TransformDirection(moveAmount);
newVelocity.y = currentYVelocity;
rb.velocity = newVelocity;
Debug.DrawRay(transform.position, newVelocity);
}```