# How do I lock the angle of rotation at a certain degree

Get help using Construct 2

### » Tue Mar 25, 2014 7:59 pm

Hi

I m creating a game wherein my character is holding a missile launcher in his hand, and the launcher rotates according to the mouse pointer. But in my case it rotates 360 degrees, I just want it to rotate around 110 degrees only and then stop. I have seen a few other threads but didn't get the exact technique of doing it. If people are finding it hard to understand than just think of a cannon, there are games where the cannon moves according to the mouse, but only till a set angle, not 360 degrees. I have attached a capx(not my original game work, just a block file). I want the rotation to be locked at a certain angle, can anyone please help me with it.

Thanks,
Karan
You do not have the required permissions to view the files attached to this post.
B
5
S
1
Posts: 16
Reputation: 408

### » Tue Mar 25, 2014 8:37 pm

Here is a start. If the canon goes beyond 55 degrees from 0 either direction it snaps back to 0 degrees.
You do not have the required permissions to view the files attached to this post.
B
17
S
4
G
3
Posts: 172
Reputation: 1,933

### » Wed Mar 26, 2014 7:12 am

I don't want it that way, I want it to lock at the 55 degree angle if its more than that, or at the 0 degree angle if its less than that, something like that.
B
5
S
1
Posts: 16
Reputation: 408

### » Wed Mar 26, 2014 8:28 am

Clamp(A, Min, Max) : return A if A is between Min and Max, Min is A is inferior to Min, Max if A is superior to Max

However, angles are cyclic, so I don't know how the engine would react in that case
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

### » Wed Mar 26, 2014 8:34 am

@Aphrodite,

Just thinking out loud: Wouldn't using startangle+degrees for max and startangle-degrees for min solve that issue?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

### » Wed Mar 26, 2014 8:54 am

LittleStain wrote:@Aphrodite,

Just thinking out loud: Wouldn't using startangle+degrees for max and startangle-degrees for min solve that issue?

Not sure, since I think C2's angle logic passes from 0 to 350 and not to -10 for exemple (not 100% sure about that), so if you clamp it to -10, it'll never clamp it

However, by using angle() I think you should be able to go through:
I suggest using a function with One parameter:
On call Function "Normal_Angle" : Set return value to Angle(0, 0, cos(Function.Param(0), sin(Function.Param(0))

Set angle to : clamp(Function.Call("Normal_Angle", Self.Angle), Function.Call("Normal_Angle", Min_Angle), Function.Call("Normal_Angle", Max_Angle))

Where Min_angle and Max_Angle are the limit angles, that should work even if C2 changes it's way to interpret angles I think, not tested
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

### » Wed Mar 26, 2014 9:03 am

Aphrodite wrote:
LittleStain wrote:@Aphrodite,

Just thinking out loud: Wouldn't using startangle+degrees for max and startangle-degrees for min solve that issue?

Not sure, since I think C2's angle logic passes from 0 to 350 and not to -10 for exemple (not 100% sure about that), so if you clamp it to -10, it'll never clamp it

However, by using angle() I think you should be able to go through:
I suggest using a function with One parameter:
On call Function "Normal_Angle" : Set return value to Angle(0, 0, cos(Function.Param(0), sin(Function.Param(0))

Set angle to : clamp(Function.Call("Normal_Angle", Self.Angle), Function.Call("Normal_Angle", Min_Angle), Function.Call("Normal_Angle", Max_Angle))

Where Min_angle and Max_Angle are the limit angles, that should work even if C2 changes it's way to interpret angles I think, not tested

Yeah, guess you're right. I believe last time I tried something with clamp and angle I made sure that in the calculation the startangle was considered to be 180 and did the calculation from that, so the clamp would always be returned between 0 and 360. And calculating it back to the desired ingame angle.
I've been out of C2 for a while, so stepping back on the bicycle ..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

### » Wed Mar 26, 2014 9:33 am

Don't think its working for me

Can anyone modify the capx and show me how it works???
B
5
S
1
Posts: 16
Reputation: 408

### » Wed Mar 26, 2014 9:47 am

Capx using the code @Aphrodite suggested:
You do not have the required permissions to view the files attached to this post.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

### » Wed Mar 26, 2014 10:11 am

Thanks a lot for your [email protected], I'll check the capx as soon as I reach home..
B
5
S
1
Posts: 16
Reputation: 408

Next