Kristoffer Darj Posted April 25, 2014 Share Posted April 25, 2014 Hello. I'm trying to follow http://gamemechanicexplorer.com/#homingmissiles-1 but my missiles end up pointing in the wrong direction all the time. So I simplified and removed basically everything but the rotation of the bullet. But even with a centered stationary bullet it ends up facing in another direction than where the pointer is. Missile.prototype.update = function() { var targetAngle = this.game.math.angleBetween( this.x, this.y, this.game.input.activePointer.x, this.game.input.activePointer.y ); this.rotation = targetAngle;}; I'm using 2.0.3Any thoughts on what might be wrong here? Link to comment Share on other sites More sharing options...
jackrugile Posted April 25, 2014 Share Posted April 25, 2014 Yeah, I had the same results when messing with that code. It works in the version he is using: 2.0.3 with some patches from 2.0.4, but not in just the plain 2.0.3. As for the difference between the two... I have no idea what is going on there. My guess is it has something to do with calculating the mouse position with respect to the offset of the canvas element, but I'm not sure. Let me know if you find a solution, or just use that patched version Link to comment Share on other sites More sharing options...
Kristoffer Darj Posted April 25, 2014 Author Share Posted April 25, 2014 Alright thanks. Link to comment Share on other sites More sharing options...
wolfkabal Posted May 23, 2014 Share Posted May 23, 2014 Hello. I'm trying to follow http://gamemechanicexplorer.com/#homingmissiles-1 but my missiles end up pointing in the wrong direction all the time. So I simplified and removed basically everything but the rotation of the bullet. But even with a centered stationary bullet it ends up facing in another direction than where the pointer is. Missile.prototype.update = function() { var targetAngle = this.game.math.angleBetween( this.x, this.y, this.game.input.activePointer.x, this.game.input.activePointer.y ); this.rotation = targetAngle;}; I'm using 2.0.3Any thoughts on what might be wrong here? I ran into the same issue with this, but not from the bullet example but the lightning example. I ended up using physics.arcade.angleToPointer(this.object) it basically just performs a Math.atan2(y1-y2, x1-x2). This seems to be the same thing that math.angleBetween is doing, but maybe just a version mismatch. Link to comment Share on other sites More sharing options...
Withjam Posted June 16, 2014 Share Posted June 16, 2014 I am running into an issue in that my sprites are built vertically but the rotation angle is calculated from the right side it seems. The example of rotating toward pointer uses an arrow sprite that is pointing to the right so that the calculation is correct. Am I missing something simple or is there a way to tell it to rotate starting from the top (while anchored in the center)? Or is the only solution to offset the calculation by 90 degrees? Link to comment Share on other sites More sharing options...
lewster32 Posted June 16, 2014 Share Posted June 16, 2014 Either offset the angle or align your sprites to the right so they match the starting angle. Link to comment Share on other sites More sharing options...
Recommended Posts