It is currently Thu May 23, 2013 5:59 am

 All times are UTC

 Page 1 of 1 [ 5 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Determine Collision surface?Posted: Wed Nov 02, 2011 4:01 am
 Grand Optimizer

Joined: Mon Jan 17, 2005 6:01 pm
Posts: 352
Has anyone ever had to figure out which side of a 2D sprite a collision occurred on?

Im using pixel-perfect collision detection and I do need to determine it. My best idea at the moment is during the pixel collision routine, upon a successfully collision, save the x,y value of the pixel in the sprite to a variable, then caclulate where that pixel is on the sprite and go from there.

not sure if it will work, and also not sure if theres a simpler way?

(bearing in mind its not a sidescrolling platformer, it's a top down with all manner of rotations and possible 'approach vectors' from other sprites)

Thanks!

_________________
"None are more hopelessly enslaved than those who falsely believe they are free."
"It is no measure of health to be well adjusted to a profoundly sick society."
"Hope is the first step on the road to dissapointment." -Jonah Orion
http://tankzgame.blogspot.com

Top

 Post subject: Re: Determine Collision surface?Posted: Wed Nov 02, 2011 8:43 am
 Bibliotherapist

Joined: Wed Nov 03, 2004 1:28 pm
Posts: 6716
Location: Oxford, Englandshire
Not sure of your requirement, but I would look at the relationship between the centres of your objects (or whatever 'handle' you are using to position the sprites).

_________________
20 GOTO 10

Top

 Post subject: Re: Determine Collision surface?Posted: Wed Nov 02, 2011 11:24 am
 Corpse Bride

Joined: Tue Jul 01, 2008 11:44 pm
Posts: 2217
Location: England
Not sure of your requirement, but I would look at the relationship between the centres of your objects (or whatever 'handle' you are using to position the sprites).

This depends on the step size of course. A big step could cause the centres to cross, and yield incorrect results.

My preferred method is to look at the relative velocity between the two objects. That vector can be used to determine which side, or it can be used to directly to calculate what happens next.

_________________
I ain't pushing no moon buttons.

Top

 Post subject: Re: Determine Collision surface?Posted: Wed Nov 02, 2011 8:58 pm
 Grand Optimizer

Joined: Mon Jan 17, 2005 6:01 pm
Posts: 352
Not sure of your requirement, but I would look at the relationship between the centres of your objects (or whatever 'handle' you are using to position the sprites).

I could certainly calculate the vector between the 2 sprites at the time of collision, but the problem is that either of them could be rotated at any angle during the collision. I've thought about a method something like this:

1) Save the position of each sprite at the time of impact
2) Use that to calculate the relative vectors of the 2 objects
3) Figure based on the rotation of the one sprite, and the vector of the other, calculate side of impact

Kindof like, "If Im here, and he's there, and im facing this way, it could only have collided with surface X"..
I got thinking about that kindof logic last night, and im not sure how accurate it would be. I'l give it a try, and see how it works out.

_________________
"None are more hopelessly enslaved than those who falsely believe they are free."
"It is no measure of health to be well adjusted to a profoundly sick society."
"Hope is the first step on the road to dissapointment." -Jonah Orion
http://tankzgame.blogspot.com

Top

 Post subject: Re: Determine Collision surface?Posted: Wed Nov 02, 2011 10:11 pm
 Dexterous Droid

Joined: Wed Aug 18, 2004 7:40 pm
Posts: 3735
Location: South Africa
I think if your objects aren't convex you're going to struggle, because all sorts of weirdness might occur.

What are you going to use the collision direction for? If it's to model a reaction force on the two objects I'd say that's probably nigh-impossible given only pixel data.

_________________
Whatever the mind can conceive and believe, it can achieve

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 5 posts ]

 All times are UTC

#### Who is online

Users browsing this forum: Baidu [Spider] and 1 guest

 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 forum

Search for:
 Jump to:  Select a forum ------------------ Forums    Forum Rules and Posting Guidelines Wiki Discussion    Help    Content Issues Game Programming Discussion    C and C++ Game Programming    Java Game Programming    Language Agnostic Programming    .NET Game Programming    VB Game Programming    Mobile Game Programming    Web-Based Game Programming    Other Languages    OpenGL Development    Direct X Development Game Development Discussion    Game Design    Game Media Off-Topic Discussion    Announcements    Off-Topic    Community Projects    News