# How to set a maximum turret rotation with touch?

1 favourites
• 7 posts
From the Asset Store
A whole set you need to create a gorgeous winter 2d game
• Hello,

I'm trying to make something where the user uses touch to direct fire.

As you can see, I have no idea what I am doing.

This works in a way, but the left and right side their angles differ from where I set the turret sprite (horizontal X position).

I suspect it has something to do with the Touch coordinates messing with the numbers of the max angle.. but I'm not sure.

I just want the turret to go max 200 degrees (which is the max angle left) and 340 degrees (max angle right).

The turret starts with an angle of 270 (pointing up).

Any ideas?

Regards

• Try this:

Turret set angle to clamp(angle(Turret.x, Turret.y, Touch.x, Touch.y), -160, -20)

• Thanks!! That works like a charm.

You are a very helpful member.

I was wondering though, how did you get to the values -160 and -20?

Thanks again.

• -160 is the same as 200 degrees.

angle() expression returns negative values for angles between 180 and 360.

• ## Try Construct 3

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

Construct 3 users don't see these ads
• OK thanks. Why does it return negative values between only 180 and 360 though? That makes it confusing to me :P

• I don't know why, it's just the way it works :)

Because the same angle can be expressed by different numbers, when dealing with angles you should try using specific conditions and expressions. For example, instead of lerp() use anglelerp(), instead of "Is between values" use "Is between angles" etc.

• Thanks for the explanation. I still need to process it, but now I know how it works.

• 7 posts