And here is some code showing the effect of multiple gravity vectors on multiple objects. The arrow keys alter the gravity of two of the spheres.
phy start
sync on
sync rate 60
autocam off
color backdrop 0
make matrix 1, 500, 500, 100, 100
position matrix 1, -200, -50, -200
Rem PJY - we're going to have 20 cube objects plus 4 sphere objects.
Rem PJY - the 20 cube objects are low mass things flying about in space whereas
rem PJY - the 4 sphere objects are large mass things of fixed XYZ location.
Rem PJY - the spheres will be coloured red
Rem PJY - essentially this code simulates the effect of the 4 spheres' gravity
Rem PJY - on the 20 cubes
for i = 1 to 20
make object cube i, 5
position object i, rnd(20) - 20, rnd(20) - 20, rnd(20) - 20
color object i, rgb(rnd(255), rnd(255), rnd(255))
set object light i, 1
set object ambient i, 1
phy make rigid body dynamic box i
phy set rigid body linear velocity i, rnd(10) - 10, rnd(10) - 10, rnd(10) - 10
phy set rigid body mass i, rnd(6) + 1
next i
for i = 21 to 24
make object sphere i, 10
position object i, rnd(50) - 50, rnd(50) - 50, rnd(50) - 50
color object i, rgb(255, 0, 0)
set object light i, 1
set object ambient i, 1
phy make rigid body dynamic sphere i
phy set rigid body mass i, 100
next i
Rem PJY - get rid of the default gravity
phy set gravity 0, 0, 0
position camera 0, 150, 30, 150
point camera 0, 0, 0
mass = 100
mass1 = 100
mass2 = 100
null = make vector3(1)
repeat
Rem PJY - update the boxes
for i = 1 to 20
for j = 1 to 4
set vector3 1, object position x(25 - j) - object position x(i), object position y(25 - j) - object position y(i), object position z(25 - j) - object position z(i)
normalize vector3 1, 1
if j = 1 then multiply vector3 1, mass
if j = 2 then multiply vector3 1, mass
if j = 3 then multiply vector3 1, mass2
if j = 4 then multiply vector3 1, mass1
phy add rigid body force i, x vector3(1), y vector3(1), z vector3(1), 5
next j
next i
if upkey() > 0
color object 21, rgb(0, 255, 0)
mass1 = 200
phy set rigid body mass 21, mass1
endif
if downkey() > 0
color object 21, rgb(255, 0, 0)
mass1 = 100
phy set rigid body mass 21, mass1
endif
if leftkey() > 0
color object 22, rgb(0, 255, 255)
mass2 = 400
phy set rigid body mass 22, mass2
endif
if rightkey() > 0
color object 22, rgb(255, 0, 0)
mass2 = 100
phy set rigid body mass 22, mass2
endif
text 0, 0, "mass1 & 2: " + str$(mass1) + " " + str$(mass2)
phy update
sync
until spacekey() > 0
null = delete vector3(1)
phy end
flush video memory
end
Cheer if you like bears! Cheer if you like jam sandwiches!
"I highly recommend Philip" (Philip)