Im trying to implement a rope swing into my game, i have a bit of experience with GML, but im still learning
I dont want to use the built in physics engine, instead i have made my own system based in physics
Its quite primitive, and a little messy, but it works, and i understand it, and im thinking about refining it a bit.
I have followed some tutorials and forum posts, and have managed to get a functioning rope swing, but it doesnt function
the way i want it to..
That one is based on creating an angular force using dcos() and dsin(), then into angular accelleration and angular speed,
which splits up into x and y speeds using lengthdir_x() and lengthdir_y()
The problem is that the character is locked to a "circle", so even if the character is straight above the "anchor" of the rope, it will follow the circle all the way around downwards
Im looking for a way to make the character move freely, unless the rope is "tight", so it is constricted by, but not locked to the rope, if that makes sense.
I could probably make it work with a lot of if statements and headaches, but im looking for something more elegant and stable
Thanks in advance!
I dont want to use the built in physics engine, instead i have made my own system based in physics
Its quite primitive, and a little messy, but it works, and i understand it, and im thinking about refining it a bit.
I have followed some tutorials and forum posts, and have managed to get a functioning rope swing, but it doesnt function
the way i want it to..
That one is based on creating an angular force using dcos() and dsin(), then into angular accelleration and angular speed,
which splits up into x and y speeds using lengthdir_x() and lengthdir_y()
GML:
// "Shoot" rope
if (mouse_check_button_pressed(mb_left)) {
xHook = mouse_x;
yHook = mouse_y;// - oTree.scroll;
xRope = x;
yRope = y;
ropeLength = point_distance(xHook,yHook,x,y);
ropeAngle = point_direction(xHook,yHook,x,y);
angSpeed = 0;
}
// Calc x and y forces
xDrag = -0.4*dcos(ropeAngle-90)*angSpeed;
yDrag = -0.4*dsin(ropeAngle-90)*angSpeed;
xForce = xDrag;
yForce = gameValues.grav + yDrag;
// Calc. angular force -> speed
angForce = xForce*dcos(ropeAngle-90) + yForce*dsin(ropeAngle-90);
angAcc = angForce/mass;
angSpeed += angAcc;
ropeAngle += angSpeed;
// Calc. x and y speed
xRope = xHook - lengthdir_x(ropeLength, ropeAngle-180);
yRope = yHook - lengthdir_y(ropeLength, ropeAngle-180);
xSpeed = xRope - x;
ySpeed = yRope - y;
// Move
x += xSpeed;
y += ySpeed;
The problem is that the character is locked to a "circle", so even if the character is straight above the "anchor" of the rope, it will follow the circle all the way around downwards
Im looking for a way to make the character move freely, unless the rope is "tight", so it is constricted by, but not locked to the rope, if that makes sense.
I could probably make it work with a lot of if statements and headaches, but im looking for something more elegant and stable
Thanks in advance!