Jump to content
  • Advertisement
Sign in to follow this  

Tutorials for vector based platform gaming

This topic is 4058 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I have recently worked on a little demo that bounces some objects around the screen, off of a user-created series of lines. Link to program to explain it a little better. This is all fine and good for either a 2D top-down game or a 3D game where the game field is completely flat or close to it (No elevation). What I'm looking for are good resources on how to start treating this like a 2D Super Mario side-scroller. In other words, I'd like to start putting in gravity and allow jumping, climbing and falling down slanted walls and whatever else I've missed. I'm looking for any relevant resources to begin working on this. My apolgoies if the search for such resources is trivial; I just don't know the exact name of the information I'm searching for. Any help you guys could give me is as always much appreciated!

Share this post

Link to post
Share on other sites
To implement gravity, simply increase each of the objects velocities in the downwards direction by a constant value at set intervals (in the real world, it would be 9.8 m/s every second, or equivalently 0.196 m/s every 20 ms -- or whatever your refresh rate is).

As for the objects sliding down the 'lines', you would need to implement some sort of frictional/damping force. But eitherway, you'll find that the objects will merely bounce their ways down the lines, rather than slide.

To make things more realistic however, you could implement a spinning motion of the objects. To model that, you'd generally deal with the angular momentum and moment of impulse.

So, suppose your sphere initially has angular velocity w, radius r, mass m, moment of inertia I, and it is travelling with a velocity u (which is a 2D vector). Suppose it collides with a surface with a unit normal n, and which has a coefficient of restitution e.

Then the final velocity and angular velocity (immediately after collision) will be:

v = T(u dot T) + n(e*u dot n)
W = w + r*m*(u-v)dot(T)/I

Where T is defined like so:
If n=(x,y), then T=(-y,x).

(Assuming I haven't made any mistakes. I'll recheck the math when I get back from work)

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!