Hi there..
Now probably all of u guyz have used Sketchyphysics at some point, and created physics joints in them. ![:smile: 😄](https://community.sketchucation.com/assets/plugins/nodebb-plugin-emoji/emoji/android/1f604.png?v=3cnphti9lj4)
The problem though, is that sumtimes the joints become glitchy
: they either become floppy or fall off completely...
not good...
The solution to the problem is to create a joint while the simulation is running.
Ever explored the scripts which make up Sketchyphysics? If so, u've probably seen the module "NewtonServer" sumwhere...
. this module is just about the kernel of the Sketchyphysics system. It creates nearly every physical feature of Sketchyphysics, from joints to forces to gravity and so on. ![:nerd_face: 🤓](https://community.sketchucation.com/assets/plugins/nodebb-plugin-emoji/emoji/android/1f913.png?v=3cnphti9lj4)
We need one of its methods, which is "createJoint"...
# this example creates a hinge joint
parent={grp} # a grouped object that encases the joint
child={grp} # a grouped object that is attached to the joint
type="hinge"
min=0
max=0
accel=0
damp=0
breakingForce=1000000
limits=[min,max,accel,damp,0,0,breakingForce] # parameters for the joint
xform=parent.transformation
pinDir=xform.zaxis.to_a # the axis of the joint
parentBody=DL;;PtrData.new(parent.get_attribute("SPOBJ","body",nil)) # converted parent body
childBody=DL;;PtrData.new(child.get_attribute("SPOBJ","body",nil)) # converted child body
jnt=NewtonServer.createJoint(type,xform.origin.to_a.pack("f*"),
pinDir.pack("f*"),
childBody,parentBody,
limits.pack("f*") ) # the joint itself
Important: in general, all array objects need ".pack("f*")" after them, and all grouped bodies need to be converted into DL::PtrData (by using "DL::PtrData.new({grp}.get_attribute("SPOBJ","body",nil))" ) ![:nerd_face: 🤓](https://community.sketchucation.com/assets/plugins/nodebb-plugin-emoji/emoji/android/1f913.png?v=3cnphti9lj4)
The created joint doesnt have the bugs normal joints have. (hopefully...
)
Have fun "Sketchyphysic"ing (!)
![:green_heart: 💚](https://community.sketchucation.com/assets/plugins/nodebb-plugin-emoji/emoji/android/1f49a.png?v=3cnphti9lj4)