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.
- 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”.
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.
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!
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.