• Content Count

  • Joined

  • Last visited

  1. Hello! That code worked perfectly. I used sprite.rotation as cur_dir, angleToPointer(sprite) as tar_dir and a number like 0.05 as inc (increment). Also I changed 180 and 360 to Math.PI and 2*Math.PI to make it work with radians Thanks sbat and Fricken Hamster for the quick replies!
  2. Ugh, I need to review my math! Thanks for the quick reply, though unfortunately I am still unable to get the results I need. Maybe again some math noobism... What I did was this, and it is not working properly... function rotationSide(object, pointer){ oldAngle = object.rotation; //Convert the angle to radians ranging from 0 to 2*PI if (oldAngle < 0){ oldAngle = Math.abs(oldAngle); }else{ oldAngle = 2*Math.PI - oldAngle; } x1 = object.x; y1 = object.y; x2 = object.x + Math.cos(oldAngle); y2 = object.y + Math.sin(oldAngle); x3 = pointer.worldX; y3 = pointer.worldY; return (x2-x1)*(y3-y1)-(y2-y1)*(x3-x1);}As defined by http://en.wikipedia.org/wiki/Cross_product#Computational_geometry, "the sign of tells whether lies to the left or to the right of line ", or in this case, the sign of the return should tell me if the pointer is to the left or to the right of the direction my sprite is pointing. But it is not doing that at the moment Thanks!
  3. Hello guys! Probably more a math problem than a phaser one, but still I'm breaking my head finding a solution. Maybe you can help me! Imagine I have a sprite pointing towards the direction of the red arrow. I want to make the sprite rotate slowly towards the pointer (in this image the green arrow), and to have it rotate clockwise/counter-clockwise depending on which way is faster (in this case counter-clockwise). How can I calculate if the faster way is clock/counter-clockwise, providing the sprite can be pointing wherever and the pointer could be anywhere? If I was not clear I can try to clarify better Thanks in advance!
  4. Hello everyone, I started using Phaser today and I must say I am impressed. Well done guys! I made a simple image rotate and move towards the mouse, as explained in the examples "accelerate to pointer" and "move towards object". What happens though is that when that image collides with the mouse (meaning image coordinates = mouse coordinates) the image stops and starts trembling awkwardly. Any way to make it stop facing the last position before colliding? My code: var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update });function preload() { game.load.image('player', 'assets/player.png');}function create() { player = game.add.sprite(400, 300, 'player'); player.anchor.setTo(0.5, 0.5);}function update() { if (game.physics.collide(player, this.game.input.activePointer.circle)) { player.velocity.x = 0; player.velocity.y = 0; } else { player.rotation = game.physics.moveToPointer(player, 60, this.game.input.activePointer); }}Thanks!