# How do I set angle towards object counterclockwise?

Get help using Construct 2

### » Thu Apr 03, 2014 1:49 pm

Hi.

When the player is on the left of the enemies, they aim at the players head. When on the right they do the same.
I wanted to restrict the "cone" of degrees that it applies.
Using the following.

Set angle toward clamp(Player.ImagePointX(2),180,230) clamp(Player.ImagePointY(2),180,230)

However since using clamp, when the player is on the right, the angle it moves at is clockwise. I need it to be anticlockwise.
I tried using the rotate anticlockwise function but this will not do as it doesn't "aim" at an object.

Is there a way to say Set angle toward clamp(Player.ImagePointX(2),Anticlockwise180,230) clamp(Player.ImagePointY(2),Anticlockwise180,230) or some solution?
B
8
S
2
Posts: 163
Reputation: 1,115

### » Thu Apr 03, 2014 2:06 pm

Rotate toward position and use a negative number for ccw ,worth a try ?????
What I know would fill a Book , what I don't know would fill a Library
B
37
S
12
G
29
Posts: 331
Reputation: 16,499

### » Thu Apr 03, 2014 2:13 pm

Unfortunately that doesn't work. Guess i will have to learn java script to build a new function of sorts. Not sure really
B
8
S
2
Posts: 163
Reputation: 1,115

### » Thu Apr 03, 2014 2:26 pm

line of sight lets you limit the cone of degrees , have you checked into using it ?
What I know would fill a Book , what I don't know would fill a Library
B
37
S
12
G
29
Posts: 331
Reputation: 16,499

### » Thu Apr 03, 2014 2:39 pm

Enemy has LOS to Player and then a subevent that checks if clockwise ,rotate to position , then a else subevent and rotate the other way , works for me !!!
What I know would fill a Book , what I don't know would fill a Library
B
37
S
12
G
29
Posts: 331
Reputation: 16,499

### » Thu Apr 03, 2014 2:53 pm

The line of sight thing doesn't work too well. It jerks the motion a lot. It snaps degrees too noticeable. Think i will redesign what i'm trying to achieve to accommodate this hiccup.

Its just frustrating considering if i do not use clamp, then there are no problems. Its only when clamp is used that it starts rotating funny.
B
8
S
2
Posts: 163
Reputation: 1,115

### » Thu Apr 03, 2014 4:07 pm

What exactly happens.

No Clamp everything rotates fine.
set my event like

If player X > enemy X : clamp 45 degrees left (135 - 220)
If player X < enemy X : clamp 45 degrees right (315 - 45)

I need this to work.
@Granpa can you please elaborate what exactly you did to make it work for you.

Would be much appreciated.
B
8
S
2
Posts: 163
Reputation: 1,115

### » Thu Apr 03, 2014 4:52 pm

i am not quite sure what you want exactly but....
try
If player X > enemy X ---------------- player set angle to anglelerp(self.angle,135,3*dt)
If player X < enemy X -------------------player set angle to anglelerp(self.angle,-135,3*dt)
feel free to change the number for it to rotate faster or slower
B
15
S
6
G
4
Posts: 277
Reputation: 3,948

### » Thu Apr 03, 2014 5:50 pm

What im trying to achieve is an enemy constantly aiming at the player. Like a turret. But i want to restrict it to only certain angles.
But
If player is on the left of the "enemy" it must restrict it to axis 135 - 220 degrees
If player on on right of the enemy it must restrict it to axis 315 - 45 degrees

If i do not use the clamp function then it is irrelevant if the player is on the left or right.
But when i use clamp, once the player is on the right, somehow the angle runs inverted. So if the player goes up, the enemy aim down.
In fact i do not think it is inverted. I think somehow it is still restricted to the first angle and not taking the second one into account.

It should rather be if the player goes up the enemy aims up.

I will investigate the lerp function and see if that helps my situation.
B
8
S
2
Posts: 163
Reputation: 1,115

### » Thu Apr 03, 2014 6:00 pm

Looks like its because i am mirroring the arms of the enemy that the angles start going lopsided and doing the inverted
B
8
S
2
Posts: 163
Reputation: 1,115

Next