flat assembler
Message board for the users of flat assembler.

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

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

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

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

22 Feb 2007, 15:26
cod3b453

Joined: 25 Aug 2004
Posts: 618
cod3b453 22 Feb 2007, 16:38
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...
22 Feb 2007, 16:38
MCD

Joined: 21 Aug 2004
Posts: 602
Location: Germany
MCD 24 Feb 2007, 04:48
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

-||__/
.|+-~
.|| ||
24 Feb 2007, 04:48
pabloreda

Joined: 24 Jan 2007
Posts: 115
Location: Argentina
pabloreda 24 Feb 2007, 13:27
search for the work of Erin Catto,
I see a example with source code, He work with momentum and the result is awesome !!
24 Feb 2007, 13:27
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum