flat assembler
Message board for the users of flat assembler.

Index > Windows > VIDEOGAMES -- To Detect Collision of a Sprite whith Rocks

Author
Thread Post new topic Reply to topic
oveja



Joined: 03 Mar 2004
Posts: 21
Location: Mexico
oveja
To Detect collision whit gravity, is necesary 2 things:

1) Detect collision Sprite whit wall or roof or floor, --> Is Easy, Very Happy
2) Sprite Reaction, --> Is HardCore. Sad

On Step 2, I do not know that to do, somebody help me.


Description: Detect Collision whit Rocks
Download
Filename: Mario.rar
Filesize: 22.63 KB
Downloaded: 95 Time(s)

Post 22 Feb 2007, 15:26
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 619
cod3b453
If the walls, roof and floor are square you can just flip the direction of movements in the x or y direction for a quick and easy reaction.

If you want a more realistic reaction, you need to define a scaling factor (called the coefficient of restitution in mechanics) for the different types of surfaces which is how "bouncy" the collisions are. (1 = perfect bounce, >1 is defy the laws of physics crazy bounce, <1 is a normal bounce and 0 if you want it to stick) This will also require some sin() and cos() functions to scale the x and y velocities correctly.

If the surfaces are not square theres a lot more trignometry involved...
Post 22 Feb 2007, 16:38
View user's profile Send private message Reply with quote
MCD



Joined: 21 Aug 2004
Posts: 604
Location: Germany
MCD
cod3b453 wrote:
If the walls, roof and floor are square you can just flip the direction of movements in the x or y direction for a quick and easy reaction.

If you want a more realistic reaction, you need to define a scaling factor (called the coefficient of restitution in mechanics) for the different types of surfaces which is how "bouncy" the collisions are. (1 = perfect bounce, >1 is defy the laws of physics crazy bounce, <1 is a normal bounce and 0 if you want it to stick) This will also require some sin() and cos() functions to scale the x and y velocities correctly.

If the surfaces are not square theres a lot more trignometry involved...

That's the essence and perfectly right.

There are just a few thing I wanted to add:
The so called collision is (almost) always divided into at least 2 parts in every computer simulation:
-collision detection
-momentum calculation

The latter of the 2 is usually neither trivial, but is manageable with some math/physics experience.
The 1st one ("collision detection") seems simpler than the 2nd one when you limit the maximum allowed speed for objects AND the minimum allowed gauge of objects AND the maximum number of objects allowed to collide at each other to 2.
If you only have non-rotated rectangular objects and coordinates then it is even more simpler!
But in fact collision detection is (probably) the most difficult part in physics-simulations if you don't limit speed (e.g. some objects is allowed to move more in a time step than another object has gauge) and allow objects to collide at any angle/border and you will get a VERY EVIL KIND OF PROBLEM!!!

I know what I'm talking about! I tried to solve that problem over and over again in 5 years and did theoretical analysis and different designs and algorithms in different programming languages and NEVER actually managed to get something that worked correct in all cases!!!

That's the reason why most professional game studios buy physics engines like the HAVOC engine instead of code one on their own. And even those professional game-physics engines contains bugs because a physics engine with no collision bugs would probably be either way to slow or would need an almost infinite complex distinction of cases! (I'm not talking about little precision bugs, but about bugs where objects that are supposed to collide may cross each other at high speed!)

_________________
MCD - the inevitable return of the Mad Computer Doggy

-||__/
.|+-~
.|| ||
Post 24 Feb 2007, 04:48
View user's profile Send private message Reply with quote
pabloreda



Joined: 24 Jan 2007
Posts: 99
Location: Argentina
pabloreda
search for the work of Erin Catto,
I see a example with source code, He work with momentum and the result is awesome !!
Post 24 Feb 2007, 13:27
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.