rotate to position on press - need help

mutinysoftmutinysoft Member Posts: 59
edited November -1 in Tech Support
hello, sorry i have a bit of a rudimentary question im making an ipad game where the character is a turret gun and wherever the player presses on the screen the turret will turn to that angle of the press and perform the shoot animation and fire the bullet in that direction.

how do i do this?

Comments

  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934
    Ok First thing you need is your default turret image needs to have the gun pointing to the right.

    Then

    When mouse button is down
    --Rotate to Angle vectorToAngle(self.position.x-game.mouseposition.x,self.position.y-game.mouseposition.y)

    Hope that helps :)
    Aaron
  • perseusspartacusperseusspartacus Member Posts: 5
    I have a simple way for you to do it:

    First off, like tenrdrmer said, have the turret image face the right.

    Then create a rule that says when mouse button is down
    --Timer every 0.000001 seconds
    --Rotate to Position X = devices.mouse.position.x Y = devices.mouse.position.y

    Also make it so that there is a small animation or whatever where the image changes to your firing image and a bullet actor spawns at an angle of 0 degrees relative to your turret actor and at the edge of your turret actor (so if you had a turret with a width of 100, spawn the bullet at an X of 50 relative to your turret actor).

    I hope this helps.
  • perseusspartacusperseusspartacus Member Posts: 5
    I forgot to mention that if you want the rotation to work smoothly, make sure it rotates very fast, like at a speed of 100,000.
Sign In or Register to comment.