# rotate THEN shoot

Member, Sous Chef, PRO Posts: 10,385
edited November -1
I'm working on a new game, and I need an object to rotate to face where the user touches on the screen and THEN fires a projectile. I've got the object to rotate just fine, but I'm sure how to best going about shooting once the object stops rotating.

anyone tackle this before?

• Member Posts: 1,693
Use rotate to angle to orient the actor (and set the target angle attribute). Then have a rule that tracks the actor's rotation compared to the target angle. Once those are equal...execute a boolean to fire. Then start the firing sequence and reset the tracking values/booleans.
• Member Posts: 3,206
You can check if the angular velocity of the Actor is 0, and then fire the projectile.
Only start checking after the turret start rotating, so it doesn't fire right away.

Or check against the angle like synthesis suggests.
• Member, Sous Chef, PRO Posts: 10,385
right now I'm checking angular velocity, but it's not as smooth as I'd like, it still fails to fire 10 -20% of the time.

I'll give the angle method a try, as long as I can dig up a tutorial that stuff is over my head.
• Member Posts: 3,206
If you are using Interpolate, you can also just use a Timer, i.e:

Interpolate: self.Rotation to [target rotation] duration: [target duration]
Timer: After [target duration] run to completion
-----[fire projectile]
• Member, Sous Chef, PRO Posts: 10,385
thanks firemaple, that really helped with the firing, but it's a different method of rotation. '

How do I take an x,y coordinate and change it to the target rotation amount? In my minds eye it involves finding the angle from the center of my object and the touched coordinate and rotating to that angle, but I'm unsure of the math.

I'm looking at the joystick demo, as that uses similar math, but I haven't nailed it down yet
• Member Posts: 8,188
Hey Mulcahy,

Not sure if this'll work, but I have 'tracker' enemies in my retro shooter.

What they do is, every .25 they rotate to position of game.playerX and game.playerY

They're set to fire every .75 seconds.

Would that help at all?

QS

Dr. Sam Beckett never returned home...
Web: http://www.quantum-sheep.com

• Member, Sous Chef, PRO Posts: 10,385
that's what I originally had, but it's not optimal for what I want to do. If the actor only needs to rotate 10 degrees, it's a pretty quick rotation compared to a 180 degrees rotation. So, from where I stand, I can either have a static rotation speed and a variable fire rate, or a variable rotation speed and static fire rate.

Using interpolate, i can set it to rotate to position over .5 seconds, but that .5 seconds is going to be the same for a 10 degree or 180 degree turn. but I could set the fire rate easily, and that's the path I'm looking at.

if I use the rotate function, I can have the rotation keep the same speed, so a 10 degree rotation is faster than a 180 degree rotation, but figuring out how to get it to fire upon stop is stumping me

I'm still playing around with the mechanics, it's not my strong suit, and it doesn't seem that complicated in my head, but getting it into GS is harder than I thought.
• Member Posts: 3,206
You want to use vectorToAngle:

myAngle = vectorToAngle(TouchX - turretX,TouchY - turretY)
• Member, Sous Chef, PRO Posts: 10,385
thanks for the help, that worked, but it wasn't exactly how I wanted it. if I was pointing at 5:00 (like on a clock face), and clicked on 7:00, it rotated counter clockwise to get there.

What I ended up doing, and this seems to work, is when you click, I set an attribute to 1, and rotate to the position. When the angular velocity is 0, and fire is 1, I spawn the bullet, and set fire back to 0.

This seems to let me keep the static rotation speed, fires as soon as it stops, and I can do rapid fire as well.

again, thanks for the help, I never would have thought of this if I didn't keep trying new things.
• Member Posts: 8,188
A little trial and error goes a long way

Dr. Sam Beckett never returned home...