Hokes Py
Hokes Py
class sd(bge.types.KX_PythonComponent):
# Put your arguments here of the format ("key", default_value).
# These values are exposed to the UI.
args = OrderedDict([
])
def update(self):
spA = self.object
scene = self.object.scene
spB = scene.objects['objB']# far the distance from each other higher
baseline of forces, but not necessarily bigger displacements
spring = 5300 # seem to be around 10 times of the mass it need to lift
damper =100 # around 20 percent of spring force
range = 1 #range of actuation, bigger value smaller undampened treshold
displacement = spA.worldTransform.inverted() * spB.worldTransform # chatGPT
trick to have the comparasions always on LOCAL cord
dispZ = displacement.translation.z
magZ = abs(dispZ) #need abs cause it is only "how far" the direction will
twist the damper force if applied, can do if spring force auto change polarity to
inverse of this
spring_force = -spring * magZ*2.2
avgSpd = spA.getLinearVelocity() - spB.getLinearVelocity()
damping_force = -damper * avgSpd[2]*range
total_force = spring_force
# Apply the total force to the objects
spA.applyForce((0,0,total_force), True)
spB.applyForce((0,0,-total_force), True)