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?