Hi there, I’m currently making a topdown style game where the player faces the mouse, and I’m trying to code it so that when the player is looking one direction and walking another (backwards) the player will actually play the animation of walking backwards. but I’m not sure how to produce a variable to determine what animation to play. =X. Anyways, Here is what I have so far. As you will see the movement looks a little off the way it is :P.
https://dl.dropbox.com/u/6629353/Topdown/WebPlayer/WebPlayer.html
Movement is just a basic character controller applying Move with the horizontal and vertical axis.
Thanks in advance! :).
I didn’t look at the webplayer, but what you’ll probably want to do is classify the direction of the movement vector with respect to the local frame, and then choose an animation based on that.
I’m not sure how you have things set up, but a good first step would probably be to transform the movement vector into the local space of the object using Transform.InverseTransformDirection(). From there it depends on how exactly you want to handle your animations, but here’s a simple example. Say you have four animations: forward, backward, sidestep left, and sidestep right. You would then split the unit circle up into four quadrants, one directly ahead, one directly behind, and one to each side, and choose an animation based on in which of these quadrants the transformed movement vector fell.
Thanks! You’re a life saver, I had like 50 lines of code (if statements) to try and determine which direction the player was facing vs the movement, Didn’t know InverseTransformDirection existed :).