How to have static actor rotate and always face direction of swipe
AtomicFX
Member Posts: 23
Hey guys, I have an actor who's position does not move. There are other enemy actors that move towards him. By touching the static actor and swiping in the direction of the other actors a projectile is thrown at the attacking actors. What I want to do is have the static actor rotate and always face in the direction of the swipe. Does anyone know how I can go about doing this?
Thanks!
Answers
The actors that swipe to the acto who rotate are swiping from the left and from the right ?
The enemy actors are moving down the screen towards the main actor. The main actor is at the bottom and when you touch him and swipe in the direction of the enemy, it shoots a projectile at them coming from the main actor's location. I just need the main actor to always rotate and face the direction of the projectile (swipe).
At the start of the swipe record the finger position into two attributes (start X and start Y).
So, when actor is touched, change start X to mouse X, change start Y to mouse Y.
Then a fraction of second later (adjust timing to taste) record the current finger position into two new attributes (end X and and Y).
So, Timer, after 0.1 seconds change end X to mouse X, change end Y to mouse Y.
Then constrain the rotation of the actor to:
Vector To Angle (end X - start X, end Y - start Y)
You can also use the same info (end X - start X, end Y - start Y) to work out the magnitude (how far your finger has travelled in that time), so you could have the speed of the bullets effect by how fast you swipe if you wanted to.
Quick (and terrible ! ) demo . . .
Link: https://www.mediafire.com/?glec6xmn48jpltt
YES!! That worked perfectly. Thanks for your help!