Basic 2D physics

BlitzPlus Forums/BlitzPlus Programming/Basic 2D physics

Regular K(Posted 2005) [#1]
Well, Im wondering how I could do basic 2D physics.

Just basically collision.

For example: I shoot a bullet, the bullet hits a ball. The ball goes flying decently close to real physics in a 2D enviroment.

I tried google for some help on this, but I couldnt find anything of use.

Thanks


Grey Alien(Posted 2005) [#2]
Firstly make everything the same object (or Types in Blitz) then you can write some generic physics functions to handle the bullet and the ball. Obviously the types need x and y coords but they also need weight (for collisions) and x speed and y speed. Also make sure the x and y is at the centre of your object.

Then when they collide you can decide which way to send both objects by setting their x and y speeds. Each frame a generic MoveObject function can move each object by their x and y speeds automatucally.

Also you need some kind of friction so that the x and y speeds slow down each frame until the objects come to rest.

If you game is overhead you won't need gravity but if it is side on you will need gravity. In this case every frame you must apply gravity to each object and see if it can fall (i.e. it is mid air now) and increase the y speed by gravity. Gravity will be your y speed "friction".

Your x speed friction can be calculated by taking the weight of the object into account and checking if it is on a surface and working out the coefficient of friction (how slidey) the surface is. Then you can decrease the x speed by the surface friction. I wouldn't bother decreasing x speed if the object is in the air as air resistance is generally negligible.

There is loads of stuff about physics on the web but you kinda want it at high school level (A level in England) so that you don't have to wave through too much crap. Hope this helps a bit.


Regular K(Posted 2005) [#3]
Hmm well that answered a bit of my questions.

I shouldve mentioned its top down.


Pongo(Posted 2005) [#4]
does this help?
http://www.blitzbasic.com/codearcs/codearcs.php?code=415

Or how about this?
http://www.blitzbasic.com/codearcs/codearcs.php?code=998


Regular K(Posted 2005) [#5]
Thank you, those should do, for now at least.


Schragnasher(Posted 2005) [#6]
this is likely the best tutorial iv found for simple 2d physics

http://www.rit.edu/~ndr0470/game_physics/


Kevin(Posted 2005) [#7]
Excellent link there, thanks for that.


Grey Alien(Posted 2005) [#8]
yeah it was kinda fun!