Change player movement direction vector x and z to match facing direction

To move player around I use lookRotation using a direction vector that has CurrentSpeedX,0,CurrentSpeedZ as components.
Those increase and decrease when the input axis are used. That makes the player only rotate 180 degrees when the X or Z component (depends on his direction) go all the way back to 0 and change sign.
And then I simply use transformtodirection on the camera to make the movements depend on the camera forward.
All this works great. The only issue im facing though is trying to push the player forward by changing the speed.
I want to make a sonic boost to be precise. But just changing the CurrentSpeedX and CurrentSpeedZ will make sonic go to the wrong direction cuz those won’t match his facing direction.

I noticed that by multiplying them by h and v (which are the horizontal and vertical axis ) will fix the issue.
But that wont do anything when they re not being pressed since their value is 0

So I wonder if there’s a way to calculate a value between -1 and 1 that will be then multiplied by the speed I want to add so the direction vector will always be facing sonic’s forward

Well, I don’t know if I misunderstood the question, but it looks to me like you are trying to achieve something really complicated, when the Transform class already provide you a forward component.

Well I fixed it guys :smiley: After 2 months of struggeling. The answer was quite simple though.

I made a vector I called CamRelativeForward which is equal to transform.forward then used InverseTransformDirection on it to make it relative to the cam forward. Then I simply multiplied the CurrentSpeedX and CurrentSpeedZ by the x and z components of this vector.

it looks like this:

Vector3 CamRelativeForward = transform.forward;
CamRelativeForward =Camera.main.transform.InverseTransformDirection(CamRelativeForward);
		
		if (BoostEnergy>0)

		if (Input.GetButtonDown("Boost")){

                        CurrentSpeedZ=60*CamRelativeForward.z;
			CurrentSpeedX=60*CamRelativeForward.x;
			
		}