Jump to content
  • Advertisement
Sign in to follow this  
Jazonxyz

Collision

This topic is 4063 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

how can I make an object stop when it collides with another object like on the legend of zelda when he hit a tree? What do I need if I already know the X axis and the Y axis and the objects' width and height?

Share this post


Link to post
Share on other sites
Advertisement
You need to represent all of your objects with rectangles during collision.

If A's left side is more than B's right side, then the objects DID NOT collide.
OR
If A's bottom side is higher than B's top side, then the objects DID NOT collide.
OR
If A's right side is less than B's left side, then the objects DID NOT collide.
OR
If A's top side is lower than B's bottom side, then the objects DID NOT collide.

If all of these were false, then the objects DID collide.
If any single one of them were true, the objects DID NOT collide.

Here's one general way to stop movement into collisions:
Backup = CurrentPosition
MoveObject()
CheckCollision( some_object )
if collision
{
Goal = CurrentPosition
CurrentPosition.x = Backup.x
CheckCollision( some_object )
if collision
{
CurrentPosition.x = Goal.x
CurrentPosition.y = Backup.y
CheckCollision( some_object )
if collision
CurrentPosition.x = Backup.x;
}
}


- Severely edited

[Edited by - Kest on May 10, 2007 9:14:09 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!