aspose file tools*
The moose likes Game Development and the fly likes Collision? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Game Development
Bookmark "Collision?" Watch "Collision?" New topic
Author

Collision?

Jake Cirino
Greenhorn

Joined: Jul 27, 2012
Posts: 17

Hi, been trying to add collision to my engine and I can't seem to find a very efficient method, any ideas?

Also, right now this is what i have (this method is called if i want to move things on the screen; x and y being the amount i want to move in each direction):



for some reason once two objects collide the program completely freezes and stops responding.

If there's a better way for me to be doing this, please let me know! Thanks.
Maxim Karvonen
Ranch Hand

Joined: Jun 14, 2013
Posts: 103
    
  11
Hi, Jake.

Apparently "this" object during your test is neither cwo obejct nor compare object. Moving "this" object does not affect any of that two colliding objects. So you move your object in endless loop.

Try to get a paper and write which objects your are comparing and how you want to move them. It may be not a simple task if there are many objects moving toward one point.

Also comparing two hashCodes looks suspicious because two different objects may have same hashCode and you may miss a collision.
Jake Cirino
Greenhorn

Joined: Jul 27, 2012
Posts: 17

Maxim Karvonen wrote:Hi, Jake.

Apparently "this" object during your test is neither cwo obejct nor compare object. Moving "this" object does not affect any of that two colliding objects. So you move your object in endless loop.

Try to get a paper and write which objects your are comparing and how you want to move them. It may be not a simple task if there are many objects moving toward one point.

Also comparing two hashCodes looks suspicious because two different objects may have same hashCode and you may miss a collision.


Thanks for the reply,

The "this" object is actually an object that places all objects relative to the value of it.

Also, without hashcode, how can i make sure that im not comparing one to itself?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18651
    
    8

To make sure those two objects are not the same object you do this:



Was that what you meant?
Jake Cirino
Greenhorn

Joined: Jul 27, 2012
Posts: 17

Paul Clapham wrote:To make sure those two objects are not the same object you do this:



Was that what you meant?

Yes, I'm not sure how .equals() would work with an object like that, but it works fine.

I managed to find the solution myself, when x and y were changing, all the of rectangles were not updated, so therefore creating a loop decreasing x and y when they weren't updating to their new positions after each loop resulted in an endless loop, thus causing the error.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Collision?