Angle lock

Get help using Construct 2

Post » 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().
Image ImageImage
B
169
S
50
G
169
Posts: 8,290
Reputation: 108,224

Post » 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
92
S
32
G
107
Posts: 5,274
Reputation: 69,959

Post » Mon Aug 22, 2016 2:37 am

Thanks I'll play around with that.
Image ImageImage
B
169
S
50
G
169
Posts: 8,290
Reputation: 108,224

Post » 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.
Image ImageImage
B
169
S
50
G
169
Posts: 8,290
Reputation: 108,224


Return to How do I....?

Who is online

Users browsing this forum: Fenix18 and 54 guests