get actor to rotate to touch?
DoomedtoFailStudio
Member Posts: 12
I've got a top-down tank game where you play as a tank with a turret on top of it. The turret and tank are separate actors. The turret is constrained to the tank, and rotates and fires a shot where you touch on the screen. So you touch, then a shot is fired, then the actor rotates. This is my problem, I need the turret actor to rotate to the specified touch X and Y position and then fire, otherwise the player may have to shoot once to get the rotation correct and again to kill an enemy.
I've tried making an attribute that records the position of the touch. Then I would have: when turret.rotation = storedtouch spawn bullet actor. I also tried putting in a timer on when the bullet is spawned.
These things didn't work, and I just can't get my mind around the issue. Should I be using a VectorToAngle function? And if so how would I do that?
Any help would be welcome and appreciated! Thank You!!
I've tried making an attribute that records the position of the touch. Then I would have: when turret.rotation = storedtouch spawn bullet actor. I also tried putting in a timer on when the bullet is spawned.
These things didn't work, and I just can't get my mind around the issue. Should I be using a VectorToAngle function? And if so how would I do that?
Any help would be welcome and appreciated! Thank You!!
Best Answer
-
sparkania Posts: 300You need to do a vectorToAngle formula.. RThurman showed me this..
on your turret
Constrain Attribute
Constrain: self.rotation to: vectorToAngle(x,y)
then replace the X and Y with the directions of your touches
there are two examples of this incorporated into this thread.
http://forums.gamesalad.com/discussion/51684/truck-with-a-trailer/p1
I was going for a truck and trailer, but the controls in the examples also included this vectorToAngle function for control of the actors.
Answers