fedora Posted November 29, 2015 Share Posted November 29, 2015 Currently, I have this script in my application to move the player in a circle using the mouse (taken from this example: http://phaser.io/sandbox/CpErwgAd/play) : var mouseX = this.input.x; var mouseY = this.input.y; theta = Math.atan2(mouseX-cX, mouseY-cY) var newX = Math.sin(theta) * radius; var newY = Math.cos(theta) * radius; rocket.x=cX + newX; rocket.y=cY + newY;I would like to change the above to key control ("A"/'D") -- but can't get the right code to work. FYI, I am using the cursor arrows for other movement with no problem. Any assistance would be greatly appreciated. Link to comment Share on other sites More sharing options...
fedora Posted December 1, 2015 Author Share Posted December 1, 2015 In case anyone is looking for the answer -- the below is thanks to the expertise of jmp909 (http://www.html5gamedevs.com/topic/18140-how-drag-sprite-around-circle/#entry107548) here's one way to do it using Sin/Coshttp://phaser.io/sandbox/gXbgAMnK/play and another using phaser's point rotation function (with a distance constraint... http://phaser.io/doc...nt.html#rotate)http://phaser.io/sandbox/wDpGcNHm/play I've taken 0 angle as the top of the circle, but that's not the normal way angles are measured so i've shifted the value accordingly Link to comment Share on other sites More sharing options...
Recommended Posts