How can I make an actor keep rotating in the same direction toward a target?

Mad Bomber

  • Posts: 5
I'm designing a behavior that will make a gun turret rotate to face the player, by rotating at a set speed rather than instantly putting itself on target. I do this by telling it: "If player position in degrees is less than direction of self, rotate counterclockwise. If it's greater, rotate clockwise."

It's working well, with one exception which you might have already predicted: when the player crosses the 360/0 degree threshold, the turret has to rotate all the way around the wrong way. How can I make the turret continue to follow the player in the same direction? I can post the behavior if it would help. Thanks very much for any advice!

thinkster

  • Posts: 149
hmmm simplest thing i can think of that might work is have a check for the turrents current angle. Check to see if it is equal to 360, and if it is true for this check then set the current angle to 0.

Then it should hopefully continue round as normal. Hopefully lol

mormord

  • Posts: 94
You may want to check my Turret Rotating Example. It is written in an old version of Stencyl, but you may find a few usable things in it.
http://www.stencyl.com/game/play/5857
It is committed to StencylForge. Otherwise, usually the commands on the Tweening tab are recommended.

gamegirlxl

  • Posts: 713
hmmm simplest thing i can think of that might work is have a check for the turrents current angle. Check to see if it is equal to 360, and if it is true for this check then set the current angle to 0.

Then it should hopefully continue round as normal. Hopefully lol

I am somewhat suspicious of using EXACT numbers in situations like these, since there is a chance that you might not detect that exact number.  I would suggest subtracting 360 from any angle greater than 360, and adding 360 to any angle less than 0.