Meaningless Drivel is fun!
The moose likes Game Development and the fly likes Collision Detection nightmare Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Game Development
Bookmark "Collision Detection nightmare" Watch "Collision Detection nightmare" New topic
Author

Collision Detection nightmare

Stephen Bell
Ranch Hand

Joined: May 11, 2013
Posts: 41
Hi all!

Having some problems with my Collision routine. It all works, but I need to know when my sprite is 'falling' and after 2 days of trying to figure out how I do that, I thought I should post my code to see if see if anyone here has any suggestions!

Basically if I am on a platform, my CD routine is constantly correcting the sprites position as gravity pulls him down which is how I want it (constant gravity) But because it moves him out of collision (not colliding) and then into (colliding) and then out (not colliding) and then in (you get the idea), I can never really know when he isn't 'really' on a platform as it will report him as not being on a platform when he's basically 1 pixel above (and will be colliding in the next frame) - as well as when he is really falling.

Hope this is clear! I need to know as when he is truly falling, as I want to apply a different graphic.

Here's my code:

Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3989
    
  18

You could keep track of the last time the character was on the platform, and if the time difference is more than a second or so, then change the animation. This also looks more natural, since a person doesn't immediately "notice" he's falling.


The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
Stephen Bell
Ranch Hand

Joined: May 11, 2013
Posts: 41
Hi Stephan, thanks for this. I managed to get around the problem.

I re-wrote my entire collision detection system so that gravity is switched off when my character is on a platform so it doesn't constantly 'fall' into the platform. Cheers.
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Collision Detection nightmare
 
jQuery in Action, 3rd edition