# Rotation Speed on Set Angle

Get help using Construct 2

### » Thu Aug 09, 2012 8:38 pm

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?

Thanks,

Ed
B
94
S
29
G
11
Posts: 1,545
Reputation: 20,993

### » Thu Aug 09, 2012 8:39 pm

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.
Discmach2012-08-09 20:47:11
B
15
S
5
G
2
Posts: 154
Reputation: 3,076

### » Thu Aug 09, 2012 8:48 pm

I suspect you will need to use lerp or some such fancy mathematical function.

Check out this post for a great explanation: http://www.scirra.com/forum/lerp-opacity_topic55210_page1.html

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.Wastrel2012-08-09 21:06:56
Don't see the fnords and they won't eat you!
B
75
S
16
G
12
Posts: 322
Reputation: 11,608

### » Thu Aug 09, 2012 9:14 pm

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)
B
79
S
24
G
54
Posts: 4,749
Reputation: 40,761

### » Thu Aug 09, 2012 9:29 pm

Yeah, @r0j0hound's solution is better. I realized after I checked that the lerp has too much of a cool down near the end.
Don't see the fnords and they won't eat you!
B
75
S
16
G
12
Posts: 322
Reputation: 11,608

### » Thu Aug 09, 2012 9:39 pm

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.
B
94
S
29
G
11
Posts: 1,545
Reputation: 20,993

### » Thu Aug 09, 2012 9:46 pm

Worked perfect. Actually just added a subevent under the event to check the distance for the Every Tick. Perfecto! Thanks a ton :)
B
94
S
29
G
11
Posts: 1,545
Reputation: 20,993

### » Thu Aug 09, 2012 10:03 pm

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.
B
94
S
29
G
11
Posts: 1,545
Reputation: 20,993

### » Fri Aug 10, 2012 7:25 pm

No, it sets the angle. I shouldn't be zero.
http://dl.dropbox.com/u/5426011/examples13/turrets.capx
B
79
S
24
G
54
Posts: 4,749
Reputation: 40,761

### » Fri Aug 10, 2012 8:44 pm

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 :).
B
94
S
29
G
11
Posts: 1,545
Reputation: 20,993

Next