A Moving Tribute To Player Movement

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.

Leave a Reply

2 Responses to “A Moving Tribute To Player Movement”

  1. Carl Pinder says:

    I think you’re going about this the right way. While there are some complex systems, like cars, that have been developed using the physics simulations; for a space “sim” like yours it isn’t necessary or desirable. If you were designing a strict space sim with all the inherent difficulties of maneuvering in zero-g, the physics system might be a good fit.

    To give it a “space” feel you may consider inertia with dampening. If you’ll recall the original Asteroids, when the player thrusted in a particular direction the ship continued in the direction even after the thrust was released, i.e., thrust equals acceleration. However, the ship did eventually slow to a stop. The leads to better player control. To stop faster in Asteroids, you needed to rotate 180 and thrust in the opposing direction.

    Regarding rotations, you should look into Quaternions. There is a decent introduction on the Unity site: http://unity3d.com/learn/tutorials/modules/intermediate/scripting/quaternions

    • Scopique says:

      I’ve been debating over whether or not get deeper into the concept of inertia, mainly because I know someone would come along an ask about Newtonian Physics, as all space game seem to attract at least one person who demands it XD But if a bit of inertia makes things easier to control, than it might be the piece I’m looking for. Right now, the controls feel a bit TOO perfect, almost like you CAN stop and turn on a dime.

What do you think?