Good day to everybody.
I’m really enjoying the ‘Unity Games by Tutorials’, as well as the other books I have from this site, and after I successfully (thanks to the authors) cleared the BobbleheadWars Chapter, I challenged myself to use those animations that we have from the .unitypackage in the BobbleMarine-Body model. Because, well, I felt that the hero deserves something more than moonwalk regardless of direction (which surely is pretty fun too).
- created the five states in the animator;
- made transitions between them;
- created four bools for each direction;
- and inside the else branch of the FixedUpdate( ) wrote a pretty hard code of four repeating if statements conditioning Input.GetAxis “Horizontal” and “Vertical” to be more or less than 0 containing all the variations of bools for each side.
As a result I have SpaceMarine’s animations for four directions transitioning between each other pretty neatly. So if he faces direction from the camera, he walks back if I press “S” and sidesteps left and right if I press “A” or “D”, and of course when I press “W” the animation of walking forward also runs. But it makes sense only if he is facing in that one direction. When mouse moved so the hero faces, say, right side of the scene, the animations keep responding to the same Input like this:
hero facing right (the direction of the mouse input), I press “Right” or “D”, and the hero himself moves forward, but the animation played is for the sidestepping right. Same thing with the other directions.
I would appreciate if somebody could explain how to make all those animations depend also on the mouse input or the hero’s facing direction. And some better solutions instead of those if statements’ hard code.