A Moving Tribute To Player Movement

A Moving Tribute To Player Movement

Posted by on Oct 12, 2015 in Game Development

Now that I have refactored and refactored the NPC movement, the next step is to get the player moving.

Player movement is one of the “thorn in the side” tasks I never look forward to because of (say it with me) maths. Whereas the NPC movement is pretty straightforward to rough in — look at your target and move forward — player movement requires  actual frame-by-frame control. A lot of that happens in the Update() or FixedUpdate() statements, of course, but how do you get an object to behave like a flying object which has no restrictions on the axes?

My solution was to just use transform.Rotate() based on the input values for pitch (up and down), yaw (spin), and roll (just like it sounds…roll over, barrel roll, dinner roll, whatever). At the same time, if we’ve got the thrusters engaged, move forward. The result goes a little something like this:

Now, any half decent Unity developer will probably tsk tsk at this, but that’s OK. I know the ideal situation would be to employ my second Achilles Heel, the physics, and use the AddForce() and AddTorque() and all that, and I tried, but the results were far less than stellar. I’ve not gotten my head around any information dealing with quaternions and euler angles and the physics. I really wish I could, or that I could find a “Unity Player Motion With Physics For Dummies” lesson out there that could help. Most discussion on movement controllers I’ve found have been either in 2D, or have concerned themselves with ground based movement.

For now, though, this serves my purpose of being able to have the player move from point to point under the user’s control, so I can start working on other systems that require the player to be present or to engage in interactions.