rtlehr Posted November 25, 2014 Share Posted November 25, 2014 Hey all, Is there a way to move a sprite towards another sprite? Like the example below, but instead of moving towards a pointer, move the objects towards another sprite. http://examples.phaser.io/_site/view_full.html?d=arcade%20physics&f=move+towards+object.js&t=move%20towards%20object Thanks,Ross Link to comment Share on other sites More sharing options...
valueerror Posted November 25, 2014 Share Posted November 25, 2014 arcade or p2 physics ? Link to comment Share on other sites More sharing options...
rtlehr Posted November 25, 2014 Author Share Posted November 25, 2014 Arcade Link to comment Share on other sites More sharing options...
valueerror Posted November 25, 2014 Share Posted November 25, 2014 ok.. i'm not really good in arcade physics but you could use game.physics.arcade.angleBetween(object, target);to get the angle between the 2 objects and apply the angle to the objects body and then set a velocity.. that should work rtlehr 1 Link to comment Share on other sites More sharing options...
rtlehr Posted November 25, 2014 Author Share Posted November 25, 2014 ok, thanks. I'll try that. Link to comment Share on other sites More sharing options...
lewster32 Posted November 25, 2014 Share Posted November 25, 2014 As well as moveToPointer there's a moveToObject method:game.physics.arcade.moveToObject(sprite, targetSprite, 200); Link to comment Share on other sites More sharing options...
rtlehr Posted November 25, 2014 Author Share Posted November 25, 2014 Thanks, that worked well. This is what I ended up withupdate: function() { radians = game.physics.arcade.angleBetween(ufoSprite, humanSprite); degrees = radians * (180/Math.PI); game.physics.arcade.velocityFromAngle(degrees, 300, ufoSprite.body.velocity); } Umz 1 Link to comment Share on other sites More sharing options...
rtlehr Posted November 25, 2014 Author Share Posted November 25, 2014 I saw the "moveToObject" in the docs, but it said that "The display object does not continuously track the target. If the target changes location during transit the display object will not modify its course" and my "human" sprite is running from the UFO, so I did not think it would work. Link to comment Share on other sites More sharing options...
Recommended Posts