object slowly rotates towards mouse

Get help using Construct 2

Post » Mon Dec 24, 2012 8:29 am

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.
B
25
S
7
G
5
Posts: 185
Reputation: 5,056

Post » Mon Dec 24, 2012 8:46 am

Easy I think.

-Every Tick or Every X seconds
-If angle ship != mouse
-rotate X degrees toward angle(....)
Thats the concept

If you need an example I will make you one but please try it by yourself ^^
B
15
S
6
G
6
Posts: 512
Reputation: 5,550

Post » Mon Dec 24, 2012 8:46 am

Use the rotate towards position action on the sprite?

B
134
S
65
G
16
Posts: 1,766
Reputation: 19,190

Post » Mon Dec 24, 2012 10:23 am

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.
B
25
S
7
G
5
Posts: 185
Reputation: 5,056

Post » Mon Dec 24, 2012 10:33 am

An example would be great.

Another thing you can try is Every 0.1 seconds with alspals code ;)
B
15
S
6
G
6
Posts: 512
Reputation: 5,550

Post » Mon Dec 24, 2012 10:36 am

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.
B
87
S
18
G
9
Posts: 2,455
Reputation: 14,834

Post » Mon Dec 24, 2012 10:53 am

Thank you all three, I will give the degree * 60 * dt a try with rotate towards position.
B
25
S
7
G
5
Posts: 185
Reputation: 5,056

Post » Thu Dec 27, 2012 2:31 pm

Hi just to follow up, the combination of the above worked perfectly thanks.
B
25
S
7
G
5
Posts: 185
Reputation: 5,056

Post » Thu Dec 27, 2012 3:33 pm

To get a really smooth movement, you could use lerp. That way there would never be an abrupt stop.
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400


Return to How do I....?

Who is online

Users browsing this forum: tatogame and 27 guests