Sign in to follow this  

Tutorials for vector based platform gaming

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this