The most important thing to remember is that good collision detection
should be prohibitive, not reactive. By this i mean when the player
attempts to move in a direction, check if the player CAN move in that
direction, ie if there is anything there first. If he can't move the
player as close as possible to the object and refuse any further motion
in that direction.
function move(x,y){
if(player._x+x<hittableObjectsLeftSide){
player._x = hittableObjectsLeftSide-1;
}else{
player._x+=x;
}
}
Very inelegant, but you get the idea. Radius, or what Jobe calls
circle/circle hit detection is nice, but sometimes getBounds and
rectangle hit detection is easier to implement in a less "organic" game
world. For instance in a rudimentary tile engine, circle/circle with
square characters quickly becomes near useless.
Again:
Get input
Calculate where the input will place the character
React to calculation - Either move character or don't. No woodpecker! :D
not
Get input
move character
react post collision
- Andreas
James Marsden wrote:
Hello games people,
Can anyone suggest a good resource/example of circle-line collision
detection and reaction for platform games? We have been through lots of
tutorials, including the ones in Jobe Makar's demystified book - the
simple examples work fine, but we can't get the examples to scale to a
sprite controlled by input from a user.
For example, the vector of a ball sprite falling and bouncing from a
line is processed to bounce the sprite away from the line - but what
happens when a force is constantly being applied by a user holding down
a key to run? We get a woodpecker effect :( and worse when trying to
test for collisions on multiple objects at the same time - the sprite
passes through a wall or platform because the radius offset logic is
escaping us. We've tried three different approaches to the same problem,
and each one seems to come back to the issue of correctly ordering the
reactions.
I thought the math would be the hardest part about developing games, but
that has been easy compared to the logic...
Can anyone help with a point in the right direction?
Thanks in advance,
James
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
--
- Andreas Rønning
---------------------------------------
Flash guy
Rayon Visual Concepts, Oslo, Norway
---------------------------------------
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com