PDA

View Full Version : Physics Engines



sceneshift
January 10th, 2008, 04:55 PM
Hi guys,

There are a bunch of really cool physics engines out there for AS3 now, like APE, FOAM and the more recent Motion.

I was just wondering, for a simple platform game (super mario, castlevania clone) where you have simple collision detection, gravity etc, is it worth using an entire physics engine or just stick to smaller custom built classes?

I can't decide which method to go for so I'd really appreciate your view on this.

Sirisian
January 10th, 2008, 09:13 PM
Writing the simple equations are very good experience, so no I wouldn't use a physics engine.

You can to figure, for super mario you're dealing with a rect to rect collision check.

intersection check is below (whited out so you can try it yourself on paper first). It's the simplified form gotten from the Separating Axis Theorem, a common theorem used in physics engines. The response is something you'll have to figure out :)



if(AABB1.x < AABB2.x + AABB2.width && AABB1.x + AABB1.width > AABB2.x &&
AABB1.y < AABB2.y + AABB2.height && AABB1.y + AABB1.height> AABB2.y){
//collision
}

Charleh
January 11th, 2008, 04:56 AM
Oooh collision response can be a complicated beast if you want professional results!

sceneshift
January 11th, 2008, 05:08 AM
Thanks for the replies.

It's seems like an awful lot of work making my own classes when someone has basically already done it for me... but at the same time I don't want all that unnecessary junk clogging up the works. (like you said, it's only rect to rect).

Tough choice.

Marz
January 14th, 2008, 01:47 PM
My personal and professional opinion. Make them yourself. If you ever want to create a full game by yourself or with a team later, you will need the smaller skills that you develop from building these smaller applications yourself.

Granted, everyone buys engines and things anymore and just modifies them, but think about the power that you would have if you knew how to build the engines? Just something to think about. That's how I started getting onto more advanced topics such as artificial intelligence and the such.

oldmanwinter
January 16th, 2008, 08:01 PM
this might be splitting hairs, but whats more efficient, writing:

if((char._x>plat._x)and(char._x<plat._x+plat._width))
{
//collision
}or

if(char._x>plat._x)
{
if(char._x<plat._x+plat._width)
{
//collision
}
}i've been using the latter because i figured there would be less checks that way, but does the cpu process "and" conditions faster??

Marz
January 16th, 2008, 10:12 PM
oldmanwinter, they would probably be milliseconds off so for the sake of readability, I would choose the method that allows you to brows it better, I prefer in-line myself.