Skip to main content
GameDev.net gamedev.net
🔒 Locked

Determine the normal between two objects

Started by Mattman Sep 12, 2005 at 6:30 PM 3 replies 1k views
Original Post
Mattman
Mattman
I'm wondering if there is a well known algorithm for what I'm trying to do. I'm trying to determine how best to go about finding the equation (actually just the slope) of the normal line where to objects collide based upon the overlapping pixel(s)...or something like that. (See image below for what I mean.) I want to know if there is a way to find out what angle the object should bounce off. Any suggestions? Thanks!
Zakwayda
Zakwayda
You mention pixels, so I'm assuming these are sprites in a 2d context. This is IMO, but I think you'd have better luck representing your objects with geometric primitives for the purpose of collision detection and response. The problems you're trying to solve - finding a normal and point of collision, reflecting the velocity, etc. - all have established solutions in geometrical terms. Circles, for example, are very easy to work with.

Also, in a 2d game environment it's best not to think of lines in terms of slope (even though that's the way we learn about them in beginning algebra). That representation isn't particularly useful for 2d simulations; the vector form is to be preferred.

The problem you describe has been discussed ad infinitum on these boards, but with the search function disabled the threads may be hard to find. If you're interested in the geometric (rather than sprite-based) solution, though, I'm sure someone would be glad to explain the basics to you.
nilkn
nilkn
I'm not completely sure what you're asking for, but it seems like vector reflection might be it.

(Look at the bottom diagram on that link.)
Mattman
Mattman
Thanks for the replies, esp. whoever is "Anonymous"...that is exactly what kind of info I was looking for!! Thank you!!!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.