LittleBear says: Yes, but in the morning I'll be sober.

11.06.07

Of Options and Springs

Posted in development, everything, games, shmups at 10:07 pm by the2bears

The theme of the SHMUP-DEV Competition 2k7 Round 2 is options, those little satellite things that generally follow your ship around and somehow help out. I haven’t coded one yet, so I started to think about the best way to do it. I decided to use springs. Here’s a very simple guide to how options can be done with springs.

A spring is generally described with the equation F=-kx, where F is the force applied to return the spring to its rest state, k is the spring constant, and x is the distance the spring is stretched (or compressed). There’s also a damping factor, d, which will reduce the amplitude of the spring’s oscillations.

So, with a little manipulation of our parameters, we can have options that snap back quickly (larger values of k) or slowly (smaller values). We can have options that bounce a lot (a high damping ratio) or bounce very little. We simply apply the force F to the options position, and d to its velocity.

A spring has 2 endpoints, in my case the option and a point close to the player’s ship. It’s much easier that way than having the ship be the other endpoint. This way, I can create a spring of zero length and control the position of the option elsewhere. The position might stay at the side, in which case I update the endpoint whenever the ship moves, or it might rotate, or almost anything else. Just update the location of the endpoint and the option will follow.

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • StumbleUpon
  • Slashdot
  • Spurl
  • Technorati

2 Comments »

  1. monoRAIL said,

    June 12, 2007 at 12:53 am

    I’m using a similar system for my options in DroneSwarm – it’s the mount command that comes with Torque Game Builder. This mounts an object to a link point by a speed parameter, which approaches zero as the object gets closer to the link. Because Torque uses a speed, not a force, to mount the objects, you can’t get that springy – overshoot effect, but it’s still pretty good for making soft movement. I’m finding it works very well for making a bunch of options fly in formation with the player, but not look too stiff.

  2. the2bears said,

    June 12, 2007 at 7:50 am

    It takes a bit to get the right values, sometimes too much physics isn’t necessarily a good thing :) Often a simpler approach, or a simplified equation is the best. One thing this method doesn’t do very well is the Gradius default formation. I think they’re simply a time-delay. They move the same as the ship, just with X frames delay. Or something like that.

    Bill

Leave a Comment