GPWiki.org
GPWiki.org
It is currently Sun May 26, 2013 1:53 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Wed Nov 02, 2011 4:01 am 
Grand Optimizer
User avatar

Joined: Mon Jan 17, 2005 6:01 pm
Posts: 352
Location: Canada
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
 Profile  
 
PostPosted: Wed Nov 02, 2011 8:43 am 
Bibliotherapist
User avatar

Joined: Wed Nov 03, 2004 1:28 pm
Posts: 6719
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).

_________________
10 PRINT "Bad Monkey ";
20 GOTO 10


Top
 Profile  
 
PostPosted: Wed Nov 02, 2011 11:24 am 
Corpse Bride
User avatar

Joined: Tue Jul 01, 2008 11:44 pm
Posts: 2217
Location: England
Codehead wrote:
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
 Profile  
 
PostPosted: Wed Nov 02, 2011 8:58 pm 
Grand Optimizer
User avatar

Joined: Mon Jan 17, 2005 6:01 pm
Posts: 352
Location: Canada
Codehead wrote:
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
 Profile  
 
PostPosted: Wed Nov 02, 2011 10:11 pm 
Dexterous Droid
User avatar

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
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group