Jump to content

another noob question - overlap or collide?


daniel0514
 Share

Recommended Posts

hi, I'm trying to make a frogger-like game and I want the player to go on top of some logs, to cross to the other side.  (see images)

 

post-14040-0-30964400-1432245372.png

 

the problem is, I haven't been able to achieve it. If I set the player to collide with the logs, the player won't go over it (see image).

 

post-14040-0-18793700-1432245373.png

 

If i set it to overlap, the player just pass through the logs.

 

post-14040-0-23280900-1432245374.png

 

What is the best way to make the player go over the logs, move with them like in the original frogger game, and get safe to the other side?

Link to comment
Share on other sites

i just have this

game.physics.arcade.collide(this.player, this.logs, this.playerOverLog, null, this);

the this.playerOverLogs function isn't doing anything at the moment, I believe it isn't even necessary, I just want the player to stand over the logs so it can cross to the other side.

 

this is the code for the logs

this.logs = game.add.group();this.logs.enableBody = true;this.logs.physicsBodyType = Phaser.Physics.ARCADE;this.logs.createMultiple(4, 'log');this.logs.setAll('anchor.x', 0.5);this.logs.setAll('anchor.y', 0.5);this.logs.setAll('outOfBoundsKill', true);this.logs.setAll('checkWorldBounds', true);this.logs.setAll('body.immovable', true);
Link to comment
Share on other sites

I think you want the character to go though the logs (otherwise he couldn't reach the other side), so why not go with overlap and set his new vX speed when overlapping on a log, so that he moves as fast as the log he is on?

Link to comment
Share on other sites

You want to use overlap:

Typically, you'd use overlap for situations where you want to detect the meeting of two objects and do something, such as a player picking up a coin. Collide on the other hand would be used for situations such as bouncing off the head of an enemy, standing on a platform or a ball hitting a paddle - you want there to be a physical effect from the meeting of the two objects as well as (optionally) detecting the event.

What I would do is, on overlap run a callback which sets the character to be a child of the overlapping log. That way, it will move along with the log as it tweens back and forth. You should still be able to move the character while the log is tweening, only its x/y position will be relative to the log instead of relative to the game world, which is what you want. When the character moves from one log to another, set it as a child to the new log on the overlap callback. Make sure your overlap callback is only running once, upon entry of the new log, otherwise you'll have two callbacks fighting to keep the character as a child to their respective logs.   

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...