GameSalad

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

rotate to position on press - need help

mutinysoftmutinysoft Posts: 59Member
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 Posts: 9,934Member, Sous Chef, Senior Sous-Chef
    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

    It's not my fault I never learned to take responsibility for anything. ;)

  • perseusspartacusperseusspartacus Posts: 5Member
    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 Posts: 5Member
    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.
This discussion has been closed.