Here's a sample - the joints seem ok but the two trailing objects appear to be able to move through each other and the large box!
#constant bullet_velocity = 1000
#constant joint1 = 1
#constant joint2 = 2
type TBullet
id
start
endtype
global nObjectIndex = 0
global nBulletIndex = 1000
global oldcamx as float
global oldcamy as float
global camx as float
global camy as float
global player_object
dim bullets() as TBullet
empty array bullets()
randomize timer()
phy start
sync on
sync rate 120
set display mode 1024, 768, 32
set camera range 0.5, 35000
hide mouse
autocam off
color backdrop 0
phy set gravity 0, 0, 0
phy set continuous cd 1.0
set ambient light 20
set normalization on
rem Player controller
player_object = GetNextIndex()
make object box player_object, 20, 20, 20
position object player_object, 0, 0, -100
phy make rigid body dynamic box player_object
phy set rigid body linear damping player_object, 0.7
phy set rigid body mass player_object, 120
hide object player_object
rem cargo ship
x# = 0
y# = 0
z# = 100
cargoship = GetNextIndex()
make object box cargoship, 20, 20, 100
position object cargoship, x#, y#, z#
SetObjectColour( cargoship, rgb(64 + rnd(127), 64 + rnd(127), 64 + rnd(127) ) )
pod1 = GetNextIndex()
make object box pod1, 20, 20, 40
position object pod1, x#, y#, z# + 80
SetObjectColour( pod1, rgb(64 + rnd(127), 64 + rnd(127), 64 + rnd(127) ) )
pod2 = GetNextIndex()
clone object pod2, pod1
position object pod2, x#, y#, z# + 130
SetObjectColour( pod2, rgb(64 + rnd(127), 64 + rnd(127), 64 + rnd(127) ) )
phy make rigid body dynamic box cargoship
phy set rigid body linear damping cargoship, 0.3
phy set rigid body mass cargoship, 1000
phy make rigid body dynamic box pod1
phy set rigid body linear damping pod1, 1
phy set rigid body mass pod1, 500
phy make rigid body dynamic box pod2
phy set rigid body linear damping pod2, 1
phy set rigid body mass pod2, 500
phy make distance joint joint1, pod1, cargoship
phy set distance joint global anchor joint1, 0, x#, y#, z# + 60
phy set distance joint min joint1, 10
phy set distance joint max joint1, 50
phy build distance joint joint1
phy make distance joint joint2, pod2, pod1
phy set distance joint global anchor joint2, 0, x#, y#, z# + 110
phy set distance joint min joint2, 10
phy set distance joint max joint2, 50
phy build distance joint joint2
rem Lighting
light_object = GetNextIndex()
make light light_object
set point light light_object, 0, 100, -100
start = 0
xdelta# = -5
do
now = timer()
text 10, 20, "FPS: " + STR$(screen fps())
text 10, 40, "Camera: " + STR$(object position x(player_object), 2) + " " + STR$(object position y(player_object), 2) + " " + STR$(object position z(player_object), 2)
text 10, 60, "Bullets: " + str$(array count(bullets()) + 1)
array index to top bullets()
while array index valid(bullets())
if now - bullets().start > 10000
phy delete rigid body bullets().id
delete object bullets().id
array delete element bullets()
endif
next array index bullets()
endwhile
position mouse 512, 384
x# = object position x(player_object)
y# = object position y(player_object)
z# = object position z(player_object)
position camera x#, y# + 20, z#
rotate camera object angle x(player_object), object angle y(player_object), object angle z(player_object)
set point light light_object, x#, y# + 100, z#
remstart
position listener object position x(player_object), object position y(player_object) + 20, object position z(player_object)
rotate listener object angle x(player_object), object angle y(player_object), object angle z(player_object)
remend
oldcamx = camx
oldcamy = camy
camx = wrapvalue( camx + mousemovey() * 0.4 )
camy = wrapvalue( camy + mousemovex() * 0.4 )
x# = curveangle( camx, oldcamx, 24 )
y# = curveangle( camy, oldcamy, 24 )
phy set rigid body rotation player_object, x#, y#, 0
if upkey()
phy add rigid body local force player_object, 0, 0, 10, 2
endif
if downkey()
phy add rigid body local force player_object, 0, 0, -10, 2
endif
if leftkey()
phy add rigid body local force player_object, -10, 0, 0, 2
endif
if rightkey()
phy add rigid body local force player_object, 10, 0, 0, 2
endif
` phy add rigid body local force cargoship, 0, 0, -1000, 1
remstart
while phy get collision data() = 1
a = phy get collision object a()
b = phy get collision object b()
if IsAsteroid(a) and IsBullet(b)
phy delete rigid body b
delete object b
endif
if IsBullet(a) and IsAsteroid(b)
phy delete rigid body a
delete object a
endif
endwhile
remend
if mouseclick() = 1
if now - start > 200
x# = object position x(player_object)
y# = object position y(player_object) + 20
z# = object position z(player_object)
bullet = GetBulletIndex()
make object sphere bullet, 10, 18, 18
scale object bullet, 20, 20, 100
SetObjectColour( bullet, rgb( 255, 0, 0 ) )
position object bullet, x# + xdelta#, y# - 10, z#
if xdelta# = -5
xdelta# = 5
else
if xdelta# = 5
xdelta# = -5
endif
endif
rotate object bullet, camera angle x(), camera angle y(), camera angle z()
move object bullet, 20
ghost object on bullet
phy make rigid body dynamic sphere bullet
phy set rigid body mass bullet, 100
phy add rigid body local force bullet, 0, 0, 1000, 2
array insert at bottom bullets()
bullets().id = bullet
bullets().start = now
start = now
endif
endif
phy update
sync
loop
end
function SetObjectColour(id, colour)
set object diffuse id, colour * 0.7
set object ambience id, colour * 0.3
` set object emissive id, colour
set object specular id, rgb(255, 255, 255)
set object specular power id, 200
endfunction
function GetNextIndex()
inc nObjectIndex
endfunction nObjectIndex
function GetBulletIndex()
inc nBulletIndex
if nBulletIndex > 1100 then nBulletIndex = 1000
endfunction nBulletIndex
function IsBullet(id)
bResult = 0
array index to top bullets()
while array index valid(bullets())
if id = bullets().id
bResult = 1
endif
next array index bullets()
endwhile
endfunction bResult
"Reality Bites"