DescriptionThis script simulates realistic swinging for a ball and chain trap.
I do not recommend to chose negative maxswing-values or values above 90
How to usePaste the below scripts into an object. (Replace "obj_chain" and "obj_ball") Place the object in your room.
Hold CTRL and rightclick the object. Select "Creation code". Write "maxchains = XX" and "maxswing = XX" (You can put a value on XX)
Optional you can write "dir = XX" to declare a starting angle. Have fun.
create event:
CODE
for(i = 1;i <= maxchains;i+=1)
{
chain[i] = instance_create(x,y+4+i*8,obj_chain)
}
ball = instance_create(x,y+4+i*8,obj_ball)
dir = 0
e = 0
g = 0
step event:
CODE
for(i = 1;i <= maxchains;i+=1)
{
chain[i].x = x+lengthdir_x(4+i*8,-90+dir+i*g)
chain[i].y = y+lengthdir_y(4+i*8,-90+dir+i*g)
}
ball.x = x+lengthdir_x(4+i*8,-90+dir+i*g)
ball.y = y+lengthdir_y(4+i*8,-90+dir+i*g)
e += 1
dir = lengthdir_x(maxswing,e)
g = lengthdir_x(1,e)