owenconti Posted March 3, 2014 Share Posted March 3, 2014 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 More sharing options...
Magnifisite Posted March 3, 2014 Share Posted March 3, 2014 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. Link to comment Share on other sites More sharing options...
owenconti Posted March 3, 2014 Author Share Posted March 3, 2014 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 More sharing options...
Magnifisite Posted March 3, 2014 Share Posted March 3, 2014 Maybe the easiest type would be on collision go a bit to the left/right/up/down etc... Link to comment Share on other sites More sharing options...
Recommended Posts