Limited angle on a moving object

This forum is currently in read-only mode.
0 Favourites
• 3 posts
• Hello. Ask a petition for my english , because I use online translators.

The essence of the problem: can not create an object with a limited angle of rotation of the object on the mobile.

picture for understanding:

How we can improve this expression ?

``````clamp(angle(gun.x, gun.y, mousex, mousey), corps.Angle-30, corps.Angle+30)[/code:1ecok5id]
If you want to show the example: [url=http://dl.dropbox.com/u/1086462/rotation%20is%20limited.cap]http://dl.dropbox.com/u/1086462/rotatio ... imited.cap[/url]
Thanks...``````
• How we can improve this expression ?

``````clamp(angle(gun.x, gun.y, mousex, mousey), corps.Angle-30, corps.Angle+30)[/code:28xqihdm]

``````

Avoiding any own math like modulo etc, you have to split it to two subevents and use the 'AngleDiff' expression and the 'Angle is clockwise of' condition.

``````+ System: Always (every tick)
-> gun: Set position to object corps (image point 0)
++ System: Angle angle(gun.x, gun.y, mousex, mousey) is Clockwise from corps.Angle
-> gun: Set angle to clamp(AngleDiff(angle(gun.x, gun.y, mousex, mousey) , corps.Angle), 0, 30) + corps.Angle
++ System: Else
-> gun: Set angle to clamp(AngleDiff(angle(gun.x, gun.y, mousex, mousey) , corps.Angle) * -1, -30, 0) + corps.Angle[/code:28xqihdm]