Rotation Speed on Set Angle

0 favourites
  • 13 posts
From the Asset Store
Have you ever dreamed of playing in a Speedball game or tournament?
  • I have a gun turret that is using set angle towards my main character. Problem is it just sets the angle instantly. Is there a way to make it rotate slowly towards the character?

    I'm not really good with the physics object, is that something I should use?



  • I presume you have it set to "every tick" set angle towards main character?

    If so, making the event "every "0.2" seconds" set angle towards main character might slow it down a bit.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I suspect you will need to use lerp or some such fancy mathematical function.

    Check out this post for a great explanation:

    Based on that, I think you would need to use Sprite.Set angle -> lerp(Sprite.Angle, endAngle, speed), where speed would be some percentage which would define how fast the transition from the current angle to endAngle would proceed.

    If I have it wrong, someone will correct me.

    newt is the Master of Lerp.

  • Try the "rotate toward position" action.

    For example to rotate 100 degrees per second:

    +Every Tick

    -> Gun: Rotate 100*dt degrees toward (player.X, player.Y)

  • Yeah, R0J0hound's solution is better. I realized after I checked that the lerp has too much of a cool down near the end.

  • Thanks guys, I'm actually not using in every tick right now, it's happened if the player is a certain distance from the turret. However, I will just make that trigger a variable that will be using in the every tick.

    Thanks again.

  • Worked perfect. Actually just added a subevent under the event to check the distance for the Every Tick. Perfecto! Thanks a ton :)

  • Quick question. If you use Rotate Towards instead of Set Angle, does the .angle property of the turret always stay zero? I'm asking because I don't want to fire unless it's some what lined up with the chopper, but when I am using angle() to check the angle between the turret and chopper, it's all wacky. So I checked the angle of the turret every tick and it stays as 0 as I watch it rotate.

  • ArcadEd

    No, it sets the angle. I shouldn't be zero.

  • Oh, thanks for the example. I'll have to look back over my code and see what I did wrong. Thanks again for the help :).

  • OK, so I am running into a bit of a bug with this. It worked great with just one object, however I have some different object I want to use this same approach too. Here is a modified CAPX of yours that I added a new object too, and I am using the same code. It seems that once you get into the range of the new object, it no longer checks the DISTANCE element, only the angle of the others. Not sure if I am making sense.

    I shortened the range of all objects to test this out, but as you move around I think you will notice what is happening.

    Thanks again.

  • Actually, I think I fixed it by make sub events of the sub event.

    <img src="" border="0" />

  • Great post, this is really simple and efficient way to make turrets! One question though, how would you add 'field of fire' to the turrets? Like a rule that turret can only fire in objects that are inside cone 90 degrees in front of it?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)