# How to calculate the dot product between the input direction and a character with root motion?

I need to calculate the dot product between my character movement direction and the input being pressed by the player. When the character movement was being controlled only by code, I was using something like this:

movementInputVector = new Vector3(inputDirection.y, 0, inputDirection.x) * Time.fixedDeltaTime;
rigidbody.MovePosition(transform.position + movementInputVector);


With this movement code, it was possible to calculate the dot product using the character's tansform.forward and the movement input vector.

It happens that I discovered that my movement needs to use root motion and after this change, I can't find a way to generate a consistent dot product anymore. Already did some attempts, but none of them worked.

Firstly, I tried to use the transform.forward, as it did worked before:

MovementDirectionDot = Vector3.Dot(transform.forward, movementInputVector);


But the result was 0, no matter the direction I pressed as input.

Then I tried to use the root bone of the character as reference:

MovementDirectionDot = Vector3.Dot(rootBoneTransform.forward, movementVector);


This attempt generated inconsistent values from ~-0,07 to ~9.

Taking a look at the transform.forward values, I've noticed it doesn't change as the character moves, remaining as a vector3(0,0,1) the whole time. Also, I tried to normalize all vectors involved and the same results happened.

So I have no clue what to do now, I don't know what vector should be used in this method in order to get back the correct dot product ranging from -1 to 1. Does anyone have an insight on this?

• What values do you get from rootBoneTransform.forward, rootBoneTransform.parent.forward, and rigidbody.rotation * Vector3.forward? Aug 21 '20 at 21:21
• Thanks for the answer, here's an image showing what you asked - imgur.com/a/fuNSps4 - I actually changed my root bone, I noticed I was using the wrong one (the hip bone) instead of the actual root of the character. Using the correct root I've got better results with the forward and backward inputs (0,99 and -0,99 respectively) but if I click to any sideways input, the dot gets with strange value again. Apparently I'm close to a solution. Aug 21 '20 at 22:39

var convertedMovementVector = new Vector3(movementVector.y, 0, -movementVector.x);