its a bit old so this looks a bit messed up be cos of updates to dp, but this may help you
Spinning Top
`******************************************
`****** Spinning Top Challenge Eatery ******
`****** By Sindore ************************
`******************************************
`***((( set up program )))***
gosub program_set_up
`***||| set up array & type |||***
type spin_top
speed# as float :`this is the launch speed
wvoax# as float :`
wvoay# as float :`
wvoaz# as float :`
stpx# as float :`
stpy# as float :`
stpz# as float :`
covx# as float :`
covy# as float :`
covz# as float :`
newx# as float
newy# as float
newz# as float
spsqrt# as float :` for spin collision
sposx# as float
sposy# as float
sposz# as float
nowposx# as float
nowposy# as float
nowposz# as float
col1 as boolean :`as Integer :`collision 1
endtype
dim SPA(10000) as spin_top
`***((( type valeuse )))***
for c = 1 to 1000
SPA(c).speed# = 25
SPA(c).wvoax# = 0
SPA(c).wvoay# = 0
SPA(c).wvoaz# = 0
SPA(c).stpx# = 0
SPA(c).stpy# = 0
SPA(c).stpz# = 0
next c
`*** make a floor object ***
make object cube 1001,1
scale object 1001,500000,10,500000
position object 1001,0,-20,0
color object 1001,rgb(10,10,10)
ghost object on 1001,4
set object specular 1001, rgb(0,0,0)
set object specular power 1001, 255
set object ambient 1001,25
phy make rigid body static box 1001
`*********************************************************************
`*********************************************************************
`******<<<<<< DO/LOOP >>>>>>******
`*********************************************************************
`*********************************************************************
`start loop
do
`***<<< FPS print out >>>***
set cursor 0,0 : print "FPS: ";screen fps();" ID: ";ID
`***<<< timers >>>***
currentlaunchtime = timer() :` this is for the fire timer
`***[[[ camera contol function ]]]***
camera_control()
`***[[[ Help function ]]]***
if keystate(59) = 1 and help = 0 then help = 1
if help = 1
set cursor 0,20 : print "Press F1 To Exit Help"
help_F1()
inc thc
if thc >= 25
if keystate(59) = 1 then help = 0
endif
else
thc = 0
endif
if help = 0 then set cursor 0,20 : print "Press F1 For Help"
`***((( if escape key is pressed jump to the end of the game )))***
if escapekey() > 0 then goto end_game
`***((( fire the spining top )))***
gosub fire_spining_top
`***((( spin set up )))***
gosub spin_control
`***((( spining top collisions )))***
gosub spining_top_collisions
`***((( update physic sync and the loop )))***
gosub physic_pause
sync
loop
`*********************************************************************
`*********************************************************************
`******(((((( GOSUB`S ))))))******
`*********************************************************************
`*********************************************************************
`***((( set up program )))***
program_set_up:
`my spining top will start off as a cube
sync on : sync rate 60
phy start
`disable this for end of game print out
disable escapekey
`screen settings
`set display mode 1280,800,32 :` change this if your screen setting differ
` set up backdrop
backdrop on
color backdrop rgb(0,0,0)
` set up camera
autocam off
return
`***((( Pause the physic`s )))***
physic_pause:
`*** pause physics ***
`if returnkey() = 1 and pause = 0 then pause = 1
if keystate(25) = 1 and pause = 0 then pause = 1
if pause = 1
set cursor screen width()/2.25,screen height()/2.25 :print "Physic Paused"
`phy update 0
inc count
if count >= 25
`if returnkey() = 1 then pause = 0
if keystate(25) = 1 then pause = 0
endif
else
count = 0
phy update
endif
return
`***((( fire the spining top )))***
fire_spining_top:
if mouseclick() = 1 and ID < 1001
if (currentlaunchtime-lastfiretime) > 1000 and ID < 1001
if ID = 0 then make_spining_top()
if ID < 1001 then inc ID
if ID = 1000 then ID = 1000
angy# = camera angle y()
angx# = -camera angle X()
`make object cube ID,1
make object ID,1,0
color object ID,rgb(255,0,0)
position object ID,camera position x(),camera position y(),camera position z()
`phy make rigid body dynamic box ID
phy make rigid body dynamic convex ID,"spining top.x" : phy load rigid body dynamic convex ID,"spining top.x"
PHY SET RIGID BODY CCD ID,1
phy set rigid body linear velocity ID,SPA(ID).speed#*sin(angY#)*cos(angX#),SPA(ID).speed#*sin(angX#),SPA(ID).speed#*cos(angY#)*cos(angX#)
phy set rigid body mass offset local ID, 0.0, -2.5, 0.0
SPA(c).wvoax# = wrapvalue(PHY GET RIGID BODY ANGULAR MOMENTUM x (c)+10.5)
SPA(c).wvoay# = wrapvalue(PHY GET RIGID BODY ANGULAR MOMENTUM Y (c)+10.5)
SPA(c).wvoaz# = wrapvalue(PHY GET RIGID BODY ANGULAR MOMENTUM z (c)+10.5)
phy set rigid body angular momentum c, 0.0, SPA(c).wvoay#*1000, 0.0
lastfiretime = timer()
endif
endif
return
`***((( spin set up )))***
spin_control:
`this is to rotate SP so it spins when a collision takes place
for c = 1 to ID
if phy get rigid body exist(c) = 1
SPA(c).sposx# = object position x(c)
SPA(c).sposy# = object position y(c)
SPA(c).sposz# = object position z(c)
SPA(c).nowposx# = object position x(c)
SPA(c).nowposy# = object position y(c)
SPA(c).nowposz# = object position z(c)
SPA(c).wvoax# = wrapvalue(object angle x(c)+10.5)
SPA(c).wvoay# = wrapvalue(object angle y(c)+10.5)
SPA(c).wvoaz# = wrapvalue(object angle z(c)+10.5)
SPA(c).covx# = CURVEVALUE(PHY GET RIGID BODY ANGULAR MOMENTUM x (c),SPA(c).wvoax#,0.1) :`change to sute
SPA(c).covy# = CURVEVALUE(PHY GET RIGID BODY ANGULAR MOMENTUM y (c),SPA(c).wvoay#,0.1)
SPA(c).covz# = CURVEVALUE(PHY GET RIGID BODY ANGULAR MOMENTUM z (c),SPA(c).wvoaz#,0.1)
SPA(c).newx# = newxvalue(SPA(c).sposx#,SPA(c).wvoax#,10) :`change to sute
SPA(c).newy# = newyvalue(SPA(c).sposy#,SPA(c).wvoay#,10)
SPA(c).newz# = newzvalue(SPA(c).sposz#,SPA(c).wvoaz#,10)
endif
next c
return
`***((( spining top collisions )))***
spining_top_collisions:
`*** collision / hit controls ***
while phy get collision data ( )
a = phy get collision object a ( )
b = phy get collision object b ( )
if a > 0 and b > 0 and a < 1001 and b < 1001 and (SPA(a).col1 = 0 or SPA(b).col1 = 0)
phy set rigid body linear velocity a , SPA(a).newx#*sin(SPA(a).covx#)*cos(SPA(a).covx#) , SPA(a).newy#*sin(SPA(a).covy#)*cos(SPA(a).covy#) , SPA(a).newz#*sin(SPA(a).covz#)*cos(SPA(a).covz#) :`SPA(a).newy#*sin(SPA(a).covy#)*cos(SPA(a).covy#)
phy set rigid body angular momentum a, 0.0,SPA(a).covy#*10, 0.0
color object a,rgb(0,255,0)
phy set rigid body linear velocity b , SPA(b).newx#*sin(SPA(b).covx#)*cos(SPA(b).covx#) , SPA(b).newy#*sin(SPA(b).covy#)*cos(SPA(b).covy#) , SPA(b).newz#*sin(SPA(b).covz#)*cos(SPA(b).covz#) :`SPA(b).newy#*sin(SPA(b).covy#)*cos(SPA(b).covy#)
phy set rigid body angular momentum b, 0.0,SPA(b).covy#*10, 0.0
color object b,rgb(0,255,0)
SPA(a).col1 = 1
SPA(b).col1 = 1
endif
if a > 0 and b > 0 and a < 1001 and b < 1001 and (SPA(a).col1 = 1 or SPA(b).col1 = 1)
color object a,rgb(255,0,0)
color object b,rgb(255,0,0)
SPA(a).col1 = 0
SPA(b).col1 = 0
endif
endwhile
return
`*********************************************************************
`*********************************************************************
`******[[[[[[ FUNCTION`S ]]]]]]******
`*********************************************************************
`*********************************************************************
`***[[[ Camera Control ]]]***
function camera_control()
rem camera rotation
yrotate camera camera angle y() + mousemovex()*0.3
xrotate camera camera angle x() + mousemovey()*0.3
rem stops mouse from going upside down
if wrapvalue(camera angle x(0))>100 and wrapvalue(camera angle x(0))<120 then xrotate camera 0,100
if wrapvalue(camera angle x(0))>180 and wrapvalue(camera angle x(0))<280 then xrotate camera 0,280
rem move the camera
if upkey()=1 or keystate(17) = 1 then move camera 0,1.5
if downkey()=1 or keystate(31) = 1 then move camera 0,-1.5
endfunction
`***[[[ Help file ]]]***
function help_F1()
set cursor 0,40 : print "Press left mouse key to make spining top"
set cursor 0,60 : print "Press up or down, w or s to move camera"
set cursor 0,80 : print "Press P key to pause physic"
set cursor 0,100 : print "Press escape key to exit program"
`set cursor 0,120 : print "Empty slot"
`set cursor 0,140 : print "Empty slot"
endfunction
`***[[[ make a spining top object ]]]***
function make_spining_top()
make object cube 1,1
make object cylinder 2,1
make mesh from object 1,2
delete object 2
add limb 1,1,1
offset limb 1,1,0,1.5,0
scale limb 1,1,50,750,50
delete mesh 1
make object sphere 2,1
make mesh from object 1,2
delete object 2
add limb 1,2,1
offset limb 1,2,0,-2.25,0
scale limb 1,2,50,50,50
add limb 1,3,1
offset limb 1,3,0,-0.75,0
scale limb 1,3,550,250,550
add limb 1,4,1
offset limb 1,4,0,5.25,0
scale limb 1,4,50,50,50
delete mesh 1
make mesh from object 1,1
delete object 1
endfunction 1
`*********************************************************************
`*********************************************************************
`******{{{{{{{ GOTO`S }}}}}}}******
`*********************************************************************
`*********************************************************************
`***((( the destination from the escapekey )))***
end_game:
`*** print ending program ***
set cursor screen width()/2.25,screen height()/2.25 : print "Exiting Program"
sync
wait 2500
`*** end physic ***
phy end
end
I used
phy set rigid body linear velocity ID,SPA(ID).speed#*sin(angY#)*cos(angX#),SPA(ID).speed#*sin(angX#),SPA(ID).speed#*cos(angY#)*cos(angX#)
to fire my spinning tops.
hope this helps
soul sucking devils, twisted body of the damed, slivering slim drips from every poor, sin licking at your ears, and the smell stinging your eyes, and if you don't like it, get out of my kitchen!