object slowly rotates towards mouse

0 favourites
  • 9 posts
From the Asset Store
Total customisation of the input! You can combine inputs from all peripherals. Make your game accessible for everyone!
  • Hi,

    I am creating a 2D top down space game like Space Pirates and Zombies, but I am having difficulty getting the control method quite right, can anyone advise how i can set a ship to rotate towards the mouse position at a slow rate, essentially I dont want the ship to permanently point at the mouse just to always rotate to face the mouse.

    For example the ship would have a rotation speed variable, so if you moved the mouse very fast it wouldnt instantly point there instead it would slowly rotate towards it based upon the rotation speed.

    If anyone has played 'Space Pirates and Zombies' I would like a similar effect to that.

    Any help will be greatly appreciated. Capx would be very useful.

  • Easy I think.

    -Every Tick or Every X seconds

    -If angle ship != mouse

    -rotate X degrees toward angle(....)

    That?s the concept

    If you need an example I will make you one but please try it by yourself ^^

  • Use the rotate towards position action on the sprite?

    <img src="http://i.imgur.com/YrTmX.png" border="0" />

  • Hi,

    I have tried both of the above the problem is, it seems difficult to make the rotation work correctly, either it stops and starts rather than appearing as a continuous albeit slow rotation or it simply point directly at the mouse at all times. It is quite bothersome.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • An example would be great.

    Another thing you can try is Every 0.1 seconds with alspals code ;)

  • alspa is the right route for this

    however I would suggest

    degree * 60 * dt

    that way it's the same among different FPS rates if there are any dips or different power.

  • Thank you all three, I will give the degree * 60 * dt a try with rotate towards position.

  • Hi just to follow up, the combination of the above worked perfectly thanks.

  • To get a really smooth movement, you could use lerp. That way there would never be an abrupt stop.

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