Sorry, I did not help with spring stuff, but got carried away fooling with your code.
I added mass to object 3, but not much.
If you change the variable "impulse" to something other than zero, you
probably will have to increase the mass to 100 or more and back the
camera off to see the whole thing.
Mostly, I changed the phy make distance joint line so it handles
everything on one line, and a few other changes like spheres instead
of cubes, although you can easily change those back.
` dist-spring - try to use distance joint to make spring-damper
` program set up
phy start
autocam off
sync on
sync rate 60
color backdrop rgb(130,160,220)
position camera -5, 4, -7.5
rotate camera 0,30,0
make light 1
set directional light 1, -5, -5, 5
` create ground object
make object box 1, 50, 1, 50
`texture object 1, 1
color object 1,rgb(70,70,70)
position object 1,0,-2,0
phy make rigid body static box 1
` create the first cube
`make object cube 2, 0.75
make object sphere 2,0.75,18,18
position object 2, 0, 3, 0
color object 2,rgb(0,100,100)
phy make rigid body dynamic sphere 2
phy set rigid body kinematic 2, 1
` create the second cube
`make object cube 3, 0.75
make object sphere 3,0.75,18,18
position object 3, 0, 2, 0
color object 3,rgb(0,0,255)
phy make rigid body dynamic sphere 3
phy set rigid body mass 3,10.0
`phy make distance joint 1, 2, 3
phy make distance joint 1,2,3,object position x(2),object position y(2),object position z(2),5.0,20.0
`phy set distance joint global anchor 1, 0, 0, 3, 0
`phy set distance joint local anchor 1, 0, object position x(2), object position y(2), object position z(2)
`phy set distance joint local anchor 1, 1, object position x(2), object position y(2), object position z(2)
`phy set distance joint global axis 1, 0, 0, 1, 0
`phy set distance joint global axis 1, 0, 0, 0, 1
`phy set distance joint max 1,2
`phy set distance joint min 1,0.0
`phy build distance joint 1
`phy set distance joint spring 1, 0.0, 500.0, 1.0
impulse=0
` main program loop
do
set cursor 0, 0
print "Distance joint with spring demonstration"
print "Use the arrow keys to apply force to the object"
if upkey ( )
`phy add rigid body force 3, 75, 75, 75, 0
`phy add rigid body local force 3, 0, 150, 0, 0
phy add rigid body force 3, 0, 150, 0, impulse
endif
if downkey ( )
`phy add rigid body force 3, -75, -75, -75, 0
phy add rigid body force 3, 0, -150, 0, impulse
endif
if leftkey ( )
phy add rigid body force 3, -75, 0, 0, impulse
endif
if rightkey ( )
phy add rigid body force 3, 75, 0, 0, impulse
endif
` update simulation and screen
phy update
sync
loop
phy end
Ad Astra Per Asper