ForumsProgramming ForumCollision detection woes

1 2609
Sparkky
offline
Sparkky
14 posts
Nomad

The following is my collision detection loop, in sudocode to assist with reading.

The problem im having is that since the avatar is moving each frame, it often goes far into barrier then gets bounced back, and Ive yet to find a graceful solution to watching it vibrate maniacally against barriers


if(Avatar isn't colliding with barrier)
{
while(enviroment left to move)
{
move enviroment;
}
}else
{
while(enviroment left to move)
{
move enviroment back to last location;
}
Set Avatar velocity to 0;
}

Its a pretty simple loop, but I' curious what other solutions people have used, preferably without maniacally vibrating results.

This is my first major step into AScript which has been.. interesting.. coming from a Java / C# enviroment.

  • 1 Reply
PixelSmash
offline
PixelSmash
566 posts
Nomad

What you could do is try and predict the movement of the environment for the next frame, and then calculate from that. This way it should never cross the bounds a lot (or at all).

Also, perhaps something like this would give better results... it's a bit more cpu-intensive, but should also more accurately predict when your avatar hits the barrier.

while(enviroment left to move){
if(Avatar isn't colliding with barrier){
move enviroment;
} else {
move enviroment back to last location;
Set Avatar velocity to 0;
}
}

Showing 1-1 of 1