how to work out relative rotation?

I’m stuck on what seems to a fairly challenging part of my game design. I’m trying to make my player play different animations depending on what way the player is facing relative to the direction he is traveling (think angry bots). So far the only way I can think of is to set a variable that chooses that travel direction via key press (north = 0 north-east = 45 etc etc) and then take that away from the result of transform.localEulerAngles.y to work out the relative direction, ie if the variable = more than 180 degrees then make my guy walk backwards. Thus if i could set the ‘look at mouse’ position to always be 0 degrees i could sort this out easily.I have tried to pull apart the angry bots code for the solution to no avail.

I’ve looked at blend trees but i don’t seem to be able to find out if it will do what i want. Maybe I’m going in the complete wrong direction with this?

Any help would be greatly appreciated :slight_smile:

Thanks in advance

garf

So, you’re using Mechanim for your animations, yes? I’m not personally familiar with how this should be done leveraging Mechanim features, but it definitely sounds like blend trees would be involved.

You can discover relative angles between vectors with

and
https://docs.unity3d.com/Documentation/ScriptReference/Vector3.Dot.html

Though whether this is what you need depends on your scenario. We’d need more info to provide support. Basically it sounds like you need a variable which represents the relative angle between your look direction and your movement vector, which you could then use to determine the proper animation to play.