# Angle lock

Get help using Construct 2

### » Mon Aug 22, 2016 12:18 am

Trying to do a drag and drop type action, something like you would have for inverse kinematics, where another object's angle determines how far, and what angles it can bae dragged to.
I have something using conditionals using angledif<45 ? object.x+cos(angle(object.x,object.y,touch.x,touch.y)*clamp(distance(object.x,object.y,touch.x,touch.y),0,max) :self.x

However I'm wondering if there was a better approach.
I tried clamping the cos(angle()) to the object.angle-45 min, and object.angle+45 max, but that doesn't workout because of the -180 from angle().
B
173
S
50
G
195
Posts: 8,575
Reputation: 121,886

### » Mon Aug 22, 2016 2:27 am

If you have the center angle you can do something like

set angle to centerAngle+calmp(angle(0,0,cos(angle-centerAngle),sin(angle-centerAngle)), -45,45)
B
95
S
34
G
128
Posts: 5,494
Reputation: 81,676

### » Mon Aug 22, 2016 2:37 am

Thanks I'll play around with that.
B
173
S
50
G
195
Posts: 8,575
Reputation: 121,886

### » Tue Aug 23, 2016 1:06 am

I finally came across this formula:
object.X+cos(angle(object.X,object.Y,touch.X,touch.Y))*clamp(distance(object.X,object.Y,touch.X,touch.Y)*cos(Angle(object.X,object.Y,touch.X,touch.Y)),0,256)

Not sure why, but I had to use cos(Angle(object.X,object.Y,touch.X,touch.Y)) on the y part. It would not work with sin.

Edit: nevermind

Same deal with angle()

Edit 2:
Fixed it with anglediff... sort of.
B
173
S
50
G
195
Posts: 8,575
Reputation: 121,886