I'm not sure how to calculate the move direction on my player controller

So, I’m working on a game and basically when you move backwards or even left and right the player jumps a tiny bit and this continues as you move, also when you jump going in any of those directions you go much higher. This makes it very unsmooth and I am trying to calculate the direction the player is moving in so that if the player is moving left, right, or backwards the drag increases so that it won’t make that up and down motion. (I’m using a Rigidbody) I’m not entirely sure how to calculate the move direction as I’ve tried multiple ways, and I’m not even sure if this is the right way to go about solving this problem. I am also fairly new to unity or at least coding in it so that doesn’t really help.

A good way to get camera relative movement is with some quaternion math (don’t worry, you don’t need to understand WHY it works to know how to use it) :slight_smile:

Basically keep this principal in mind: quaternion * vector3 = vector3 rotated by the quaternion

So if you make a quaternion from your character’s Y rotation, like Quaternion.Euler(0, character.eulerAngles.y, 0), you can then multiply your movement direction like this to get a camera oriented direction:

Rigidbody.velocity = Quaternion.Euler(0, character.eulerAngles.y, 0) * new Vector3(movementLeftRight, 0, movementForwardBackward)

Then you can do whatever you want with that value like multiply it for how fast you want to go, interpolate it, or really anything else.

I would recommend using rigidbody.AddForce or rigidbody.AddRelativeForce in these situations and would recommend looking them up in the unity docs:

Sorry for the late response but I found out the problem. Since my player was in first person it would add force where ever the camera was facing. So for example if you looked straight up and went forward you would go up because that is where the camera is facing, so this could potentially make small jumps when moving if you were looking in a certain direction.