Sign in to follow this  
GMaker0507

Simulating a 2d motorcycle riding a line

Recommended Posts

Lately i have been inspired by alot of these flash motorcycle games out on various web sites. So i decided to try and make one of my own. I thought i understood enough to make a simpler version, just a motorcycle riding a line, however i now know that there is something i dont know, or that something i know is wrong. I understand vectors, and vector math, Sweep testing circles against other circles, against lines, and against vertices. I assume, for a simple simulation, thats all that i would need to know. What i have so far seems fine in my head, but when i try it out, its like crap. Can someone please give some insight, a web site, or something that will direct me the right direction.

Share this post


Link to post
Share on other sites
If you mean things like Line Rider (http://linerider.com/) then have a look at this tutorial:
Create a flash draw game like Line Rider or others
http://www.emanueleferonato.com/2007/01/08/create-a-flash-draw-game-like-line-rider-or-others-part-1/

Share this post


Link to post
Share on other sites
Assuming all you collision detection code is correct, you probably need to implement some physics.

Take a look at simulating gravity and springs. Make sure you understand the difference between kinetic energy and potential energy. Momentum is another important factor.

Basically, you need to understand Newton's laws of motion. Other than that, I can't give any advice until I know a little more about the problem. In what way does it look bad?

Share this post


Link to post
Share on other sites
Well, ive done simulations of a ball riding a line before, and that went okay:

http://enix591.deviantart.com/art/Some-Vector-Fun-82547551

However now i wanted to up it one level.

I guess if i had to choose what i think was causing the most problems i would say... the wheels interacting with the enviorment indiviually, but also affect one anothers position and velocity. Its kinda vague, i know

For example, the front wheel collides head on with a line. It should stop, and the other wheel be affected based on its position relative to the front wheel.

(A) If it is, for example, directly behind the front wheel, or in other terms if the vector to the second wheel is the same as the lines normal, then the second wheel should also stop.

(B) Or, if the vector to the second wheel is the perpendicular as the lines normal, then the second wheel should not stop, but also not continue in that path of motion,it should instead rotate based on its positioning relative to the front wheel. Then in i guess it would rotate until the bottom of the motorcycle, or the wheel hit a vertex or a line

However, a problem i just thought of as i was writing this sentence was, in the case where the D is perpendicular to N, then how should i alter the velocity of the second wheel to rotate around the first wheel and not conintue along its velocity vector.

Also another problem, how do i prioritize keeping the proper distance between each wheel, with the results from the sweep test.

In my head everything seems okay, but then again theres also something telling me im missing something.

I guess the bottom line is that everything seems fine how it is, as the motorcycle does ride the line, i could very well settle for what i have now. However

Share this post


Link to post
Share on other sites
I would use an interative method to reduce the error between where the wheels are, and where they should be. When the bike rolls into a wall, the front wheel will reject, introducing error into the constraint. You can then use a spring to correct this by pushing equally and opposite on both the wheel and the chassis it's constrained to.

This method will have noticeable error, but it is very basic to setup. You can also choose to do it at either the velocity or acceleration level for better accuracy. To truely finish the solution, then entire constraint will have to be processed on contact, so no displacement is ever introduced and the contact impulse propegates through the constraints appropriately.

So to recap: look at constraining two bodies with a spring, make it a stiff spring, then limit its axes.

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