frank84 Posted July 24, 2014 Share Posted July 24, 2014 Ok i'm kind of stuck here ... I have a a sprite that I move using the following:target.sprite.body.velocity.x += target.power/2;target.sprite.body.velocity.y -= target.sprite.body.velocity.x*1.5;I would like to know the coordinates of where the sprite will stop instantly, without having to wait for the animation of the sprite to finish. Anyone knows how I could achieve that?Thanks! Link to comment Share on other sites More sharing options...
lewster32 Posted July 24, 2014 Share Posted July 24, 2014 Technically the sprite will continue on forever, since there's nothing stopping it in the code above. If you start to use things like drag or if it collides with something, then you've got a lot more calculating to do! If your object isn't going to collide with anything, and there's no drag, consider using a tween instead, as then you know exactly where it is going, how long it'll take and that it will definitely stop at the end exactly at the position specified.// turn off physics temporarilytarget.sprite.body.moves = false;// tween the object to 500, 1000 over 2 seconds, then enable physics at the endgame.add.tween(target.sprite).to({x: 500, y: 1000}, 2000, null, true) .onComplete.add(function() { target.sprite.body.moves = true; }, this);If you need to use physics, then I have to delegate to someone with way better trigonometry skills than I have. I imagine the calculation is easy but I don't know it I'm afraid. Link to comment Share on other sites More sharing options...
frank84 Posted July 24, 2014 Author Share Posted July 24, 2014 Yeah unfortunately I need to use physics . What I want to do would be very similar to the effect found in Angry Bird, where you can see a curved line over the bird when you are about to throw the bird, and that line give you an idea where your bird will land. Link to comment Share on other sites More sharing options...
Hsaka Posted July 24, 2014 Share Posted July 24, 2014 Hey, check out this example on gamemechanicexplorer: http://gamemechanicexplorer.com/#bullets-5I suspect you can tweak it to meet your needs. frank84 1 Link to comment Share on other sites More sharing options...
frank84 Posted July 24, 2014 Author Share Posted July 24, 2014 Wow that's exactly what I was looking for, thanks a lot for that! I'll be sure to look into that and see how they do it, hopefully I can tweak it to adapt it to my game Link to comment Share on other sites More sharing options...
lewster32 Posted July 24, 2014 Share Posted July 24, 2014 Aha, a ballistic trajectory - sorry I misunderstood what it was you were needing! Link to comment Share on other sites More sharing options...
Recommended Posts