Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Best way to handle collision on route to destination?


owenconti
 Share

Recommended Posts

Hi,

 

I have an object, let's call it Player, than the user can move via mouse clicks. I am currently using the following code to move Player:

 

this.tween = this.game.add.tween(this.body).to({ x: x, y: y }, duration, Phaser.Easing.Linear.None, true);

This works great, until Player runs into a blocking object (let's call them Squares) which have immovable = true. What ends up happening is the Square block Player and Player glitches about and sometimes even teleports to the other side of Square, before continuing on to his destination. 

 

I am assuming this happens because tweens use a duration to complete the animation, which makes sense. But how can I handle when Player is blocked by a Square and his duration for the current path is now longer, because Player should go around Square rather than teleport across?

 

Thank you

Link to comment
Share on other sites

Well you can´t use tween, you should create your own pathfinding algorithm and then use a combination of tweens to move it or do the tweening yourself.

 

Thanks for the tip, I never thought about a Path system. Because Squares can be dynamic/moving all the time, would I need to create an initial path on click, and then recreate a new path for Player if he collides with a Square along the original path?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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