1
\$\begingroup\$

I'm trying to create a series of physics-enabled 'ropes', with hard limits on how far they can swing left or right. They are comprised of an oRopeRoot kinematic physics object, which generates a certain number of oRopeSections, round little objects, and finally a single oRopeEndSectionto cap it off.

These are connected by revolute joints with restricted angle of movements. Unfortunately, as you can see from this gif, they are all over the shop. I am still learning about physics joints in Gamemaker, and if anybody can look at the code below and see what might be wrong, I'd be very grateful for the learning experience.

oRopeRoot

Density: 0

Restitution: 0

Collision Group: -1

Linear Damping: 0.5

Angular Damping: 0.5

Friction: 1

(Kinematic)

Create Event:

depth = global.ForeignObjectsOnFaceLayer -1
OriginalX = x
OriginalY = y
image_alpha = 1
image_xscale = random_range(0.3,0.7)
image_yscale = image_xscale
GeneratedValues = true
RopeLength = irandom_range(20,30)
SectionsCreated = 0
EndCreated = false
ParentPore = noone

Step Event:

phy_position_x = OriginalX
phy_position_y = OriginalY - mLeftCheekFurArea.Difference


if SectionsCreated < (RopeLength - 1) {
CreateAndAttachSection()
SectionsCreated = SectionsCreated + 1
} else if SectionsCreated >= (RopeLength - 1) {
if EndCreated = false {
CreateAndAttachEndSection()
EndCreated = true
}
}

CreateAndAttachSection()

if SectionsCreated = 0 {

ParentSection = self.id
ChildSection = instance_create(ParentSection.x,ParentSection.y,oRopeSection)
physics_joint_revolute_create(ParentSection, ChildSection, ParentSection.x,ParentSection.y,-45,45,true,0,0,false,false)
ParentSection = ChildSection
ChildSection = noone

} else if SectionsCreated > 0 {
ChildSection = instance_create(ParentSection.x,ParentSection.y + 6,oRopeSection)
physics_joint_revolute_create(ParentSection, ChildSection, ParentSection.x, ParentSection.y + 6,-45,45,true,0,0,false, false)
ParentSection = ChildSection
ChildSection = noone
}

CreateAndAttachEndSection

ChildSection = instance_create(ParentSection.x,ParentSection.y + 6,oEndSection)
physics_joint_revolute_create(ParentSection, ChildSection, ParentSection.x, ParentSection.y + 6, -45, 45, true, 0, 0, false, false)
ParentSection = noone
ChildSection = noone

oRopeSection

Density: 1

Restitution: 0

Collision Group: -1

Linear Damping: 1

Angular Damping: 1

Friction: 1

oEndSection

Density: 1

Restitution: 0

Collision Group: -1

Linear Damping: 0.5

Angular Damping: 0.5

Friction: 1

\$\endgroup\$
0
\$\begingroup\$

I think I might have solved this myself. There were several problems with my specific approach which may be useful to others:

  • The pixels-to-meters scale in my physics world (found in the Physics tab of the Room window) was set far, far too low. The default value is there for a reason: once I started using this, everything calmed down an awful lot.

  • Setting a higher density for each component in the revolute joint (>= 1) also helped to calm the simulation down.

There is further illumination on this thread: https://www.reddit.com/r/gamemaker/comments/4vyop8/help_using_prismatic_joints_and_textured/

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.