Use the Force, Luke. – Obi-Wan
In the previous Part 1 and Part 2 I did what I would consider the easy stuff for tuning ship movement. This week was an attempt at getting a tuned ship movement experience while still using ApplyForce.
Goals
- Respect a top speed clamp when accelerating
- Provide a function that changes the force applied based on the current speed
- Have a method for damping when not accelerating
This weeks attempt
I realized this week that focusing more on management in my day job rather than coding has made me very rusty! I sat down for about an hour to work out how to do this and only a little bit of the dust wore off. I ended up with an experience I don’t mind the feel of but it isn’t “correct”.
Top speed
Originally I wanted to try to use damping to control the top speed and the deceleration. I wasn’t able to maintain a consistent top speed with damping enabled. I believe that damping is applied every frame and is applied as a percentage. This means that the faster you go the more speed is bled off. Rather than digging in to confirm this I decided to set damping to zero when the engines are on and to use a function (speed/top speed currently) to make sure that I’m not applying any additional force when I’m at top speed. This worked great and I thought I was done. Two problems, one my ship can go in reverse and when this happened the speed accelerated like crazy because the backwards top speed is different and two traveling at top speed if you turn the ship and attempt to accelerate no force is applied. Bummer dude.
I still don’t think I have found the correct way to account for this and if someone has a pointer to that I would be much obliged. What I am currently doing is using a dot product of the normalized velocity and the angle the ship is pointed at. If the value is less than zero I apply the full force since you are pointed in the opposite direction. That covers the backwards direction but I still haven’t found a good way to do the slightly off angle clamp. I’m going to work on that sometime in the next couple of weeks. The other thing I haven’t really covered is doing the same scale backwards. That is just a time limitation rather than not knowing how.
Function for top speed
Currently I am using speed/top speed as the force scalar and it is working fairly well so far. At a later time I’m going to make this exposed as a lua function that can be tuned per ship. For now this is functioning well enough.
Damping
Using damping to cause a deceleration has worked really well. I am currently using a value of 5 when above 1/4 of top speed and 20 when below 1/4. This lets me stop really fast and coast a little when “cruising”. Ideally when I rewrite all my ship code this will be a function as well.
Next Steps for Ship Movement
I really want to find a way to correctly control and map the top speed. This might go back to clamping the speed rather than scaling off the acceleration or actually taking into account the ship angle when scaling the force. I’ll those in the next couple of weeks. As it stands my ship can circle strafe and is actually feeling better as an experience so I am going to take a small break and design some game play or work on the look for the next couple weeks.
Sneaking in an update on art
When I get frustrated at not being able to solve something I take some advice from Micheal Abrash (Graphics Black Book – but I can’t find the chapter I mean!) and think about something else. In this weeks case I decided to fix my awful background image which was basically a noise texture. Space isn’t “space” without some nice stars and nebula’s. So I found this great old school space generation program. It took me about 5 minutes to download and create my own custom background. This is one of those pieces of software I am going to buy since it adds a ridiculous amount of “good space feel” to my game even if I’m not an artist!

I, Game Maker: Universe background
What am I thinking for this week
I think I need to take a break from physics and I may be doing one of the following:
- Re-writing all the game play classes and exposing them properly with Lua
- Adding in particle systems to make it really feel like a space game and be rewarding to shoot stuff
- Changing the shooting system to be aim with the mouse, steer with the keyboard
- Adding an enemy that is a ship to learn a bit about AI and OpenSteer
Any of the above is going to be fun to work on.
Pretty cool stuff. I came across this because I’m practically trying to do the same thing your doing and I was looking for tips on doing propulsion with a physics system (Box2D of course). I’m at close to the same stage as you are other then that. I use Lua for scripting and mostly Box2D for physics. I have a basic particle system and simple world editor as well.
Screenshot: http://img12.imageshack.us/img12/8246/roidshb3.png
its a bit different in that im also simultanously writing a simple game engine. it also runs this: http://img12.imageshack.us/img12/5149/jeepsvn1.png
no, i havent made much custom art yet 😉
Sounds like you are ahead of me! I’m really not finding much more than a 1/2 hour a week to work on this stuff but having to post every week is helping me get motivated to post what I have learned. I’m just getting into the particle system stuff and hope to post something on that this week or next.
if your happy with your ship movement id love to see a demo posted just so i can get a feel for it, i havent gotten my movement tuned very well.
i dont think im very far ahead. it definitely took a lot more time too, although i spend most of my free time writing the backend for my cousins site. he pays pretty well 🙂
anyway lately ive been less geared towards making a specific game, and more towards making this whole framework. i think its about time i just jump in and make some simple games. most of the code is there, i just need the basic start level->do things->victory->next level. right now i basically have a “playground” for everything. which is pretty great for testing. chances are youll make a real “game” before i do.
im probably over-engineering a bit, but im not sure. i even made everything component based, the important ones are “Box2DComponent” and “LuaComponent”. everything is loaded from XML. everything is network-enabled (client-server) and also i wrote the GUI classes myself. maybe i should be writing about this stuff somewhere.
ill gladly give you a demo too if you want.
oops, forgot to check the “notify of followups” 🙂
Nice post. igamemaker.com deserves an oscar.