4 Replies - 394 Views - Last Post: 25 March 2013 - 05:44 PM Rate Topic: -----

#1 Bobslobjunior  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 15-March 13

Collision Detection

Posted 20 March 2013 - 01:09 AM

Hi,
I am developing a platformer sort of game in java and it requires collision detection.

if (floor.intersects(player.player)) {
			mouseYpro = floor.y - 50;
			
		}


That is code for it at the moment, later on I will use the wasd keys.
The point is, when floor and player collide player does stop but it occilates and judders up and down.
I think this could be to do with the engine/game's refresh rate (I made both).
If you could help, that'd be great,
Thanks


Is This A Good Question/Topic? 0
  • +

Replies To: Collision Detection

#2 cfoley  Icon User is online

  • Cabbage
  • member icon

Reputation: 1954
  • View blog
  • Posts: 4,055
  • Joined: 11-December 07

Re: Collision Detection

Posted 20 March 2013 - 02:52 AM

It sounds like it's to do with the order of events but you've not given us much to go on. My guess is that the juddering is caused by a sequence of events like the following:

move
refresh
fix collisions
refresh

You should arrange your collision detection to disallow moves that would result in a collision, or change your sequence of events to refresh only after collisions have been resolved. If your engine has several threads then it could have strange effects on the order of events.
Was This Post Helpful? 1
  • +
  • -

#3 Bobslobjunior  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 15-March 13

Re: Collision Detection

Posted 25 March 2013 - 10:10 AM

Ok, thank you
Was This Post Helpful? 0
  • +
  • -

#4 CasiOo  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1391
  • View blog
  • Posts: 3,078
  • Joined: 05-April 11

Re: Collision Detection

Posted 25 March 2013 - 11:59 AM

Have you remembered to stop the player from falling when he hits the floor :)?
Was This Post Helpful? 0
  • +
  • -

#5 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 823
  • Posts: 2,539
  • Joined: 29-July 11

Re: Collision Detection

Posted 25 March 2013 - 05:44 PM

I could be way off based on the little code you posted, because it looks to e the proper strategy, but we'll need to see more.

It might have something to do with timing, but I doubt it. I get the feeling that this is probably one of those situations here your players falls(gravity + y) until it hits the floor, then you reverse direction (y - 50), which results in a cycle of:

fall
move up
fall
move up
etc...

When you should not be moving up, but keeping the player's Y position on the floor, instead. I know your posted code snippet is similar to this.

if((player.y - player.height) >= floor.y) {
    player.y = floor.y - player.height; //keep player's feet on the floor.
{


This post has been edited by farrell2k: 25 March 2013 - 05:44 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1