GameSalad

Howdy, Stranger!

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

rotate THEN shoot

jonmulcahyjonmulcahy Posts: 10,377Member, Sous Chef
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?

Comments

  • synthesissynthesis Posts: 1,693Member
    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.
  • firemaplegamesfiremaplegames Posts: 3,206Member
    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.
  • jonmulcahyjonmulcahy Posts: 10,377Member, Sous Chef
    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.
  • firemaplegamesfiremaplegames Posts: 3,206Member
    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]
  • jonmulcahyjonmulcahy Posts: 10,377Member, Sous Chef
    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
  • quantumsheepquantumsheep Posts: 8,188Member
    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 :D

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

  • jonmulcahyjonmulcahy Posts: 10,377Member, Sous Chef
    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.
  • firemaplegamesfiremaplegames Posts: 3,206Member
    You want to use vectorToAngle:

    myAngle = vectorToAngle(TouchX - turretX,TouchY - turretY)
  • jonmulcahyjonmulcahy Posts: 10,377Member, Sous Chef
    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.
  • quantumsheepquantumsheep Posts: 8,188Member
    A little trial and error goes a long way ;)

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

This discussion has been closed.