0% found this document useful (0 votes)
3 views1 page

Hokes Py

The document contains a Python script for a Blender Game Engine component that simulates a spring-damper system between two objects. It calculates the spring and damping forces based on their positions and velocities, applying these forces to create a physical interaction. The script is designed to maintain a baseline of forces while allowing for variable displacement and actuation range.

Uploaded by

nunesmax205
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Hokes Py

The document contains a Python script for a Blender Game Engine component that simulates a spring-damper system between two objects. It calculates the spring and damping forces based on their positions and velocities, applying these forces to create a physical interaction. The script is designed to maintain a baseline of forces while allowing for variable displacement and actuation range.

Uploaded by

nunesmax205
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import bge

from collections import OrderedDict

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 start(self, args):


pass

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)

You might also like