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
171
S
50
G
179
Posts: 8,382
Reputation: 113,458

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
94
S
33
G
114
Posts: 5,357
Reputation: 73,775

Post » Mon Aug 22, 2016 2:37 am

Thanks I'll play around with that.
Image ImageImage
B
171
S
50
G
179
Posts: 8,382
Reputation: 113,458

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
171
S
50
G
179
Posts: 8,382
Reputation: 113,458


Return to How do I....?

Who is online

Users browsing this forum: zenox98 and 21 guests

cron