Posts Tagged ‘Physics’

Solving the velocity problem

Last night I fiddled with my game’s physics a bit and I came close to a method of providing “drift” to the player’s ship when you change direction and add thrust.  The previous version instantly changed direction but maintained the same speed – not realistic, not elegant, and highly dangerous.  (Instant 180 degree turns would probably turn your crew and cargo into a nice thick paste coating the rear wall of your ship.)

Here’s the solution I came up with after playing Three Card Monty with the variables (I am not a math person by any means)…

currentHeading – ((directionShipIsPointing – currentHeading) * arbitraryThrustValue) = newHeading

This works great for the most part…but a problem arises when you turn the ship from, say, 5 degrees to 350 degrees…my algorithm interprets that as a change of 355 degrees, and thus the ship bounces backward for a second before coming to its correct course.  I won’t bother posting the actual code here since it’s WRONG!

Oy!  What to do?  Fortunately, Avi Pilosof just posted a thorough, illustrated and wonderful set of blog entries about this very thing.  I cought it via Silverlight Cream.  So I’m going through that and I’ll rework my physics using vectors instead of basing everything on rotations.  This will help me out with Second Life programming, too, I’m sure.