- Home /
Question resolved without answer
Calculating proper x,z values to pass to blendtree
I'm essentially trying to pass an X and Z value to my animator with min/max values of -1 to 1.
The character can rotate 360 degrees, and move on the x and y axis.
In the following image, my character is facing north. The arrows indicate character movement. Expected values for x,z are in blue.
In this image, the character is facing east.
I believe what I need to do is just offset the rotation by an angle. Just not sure how to solve this one.
Answer by Chris_Payne_QS · Jan 23, 2020 at 01:30 AM
Not sure precisely what you're trying to do, but I think you just need to calculate the velocity vector relative to the character transform:
Transform characterTrans = blah;
Vector3 worldVel = blah;
Vector3 localVel = characterTrans.InverseTransformDirection( worldVel );
Then pass localVel into the Animator.
The character transform is the movement, rotation and scale that moves (transforms) the character from the origin to it's ingame position. This function uses the inverse of that transform (which would bring the character back to the origin) but does it to the worldVel. The "Direction" postfix tells it that you only care about the direction of the vector so it doesn't apply the position offset. So if the character is rotated, this will unrotate all axes at once.