I've done so much with this, from testing new stuff to..... all kinds of crap. This is what I have....

I can't seem to make it work both ways. And if you fall, it screws it all up.... sometimes. You can use this method if you make it ONLY possible to go one way around the loop. Maybe make a ramp at the end so the player can't try to go the other way. Kill the player if they fall off. Well as crappy as it is, here's the code:
Rem Project: loop
Rem Created: Tuesday, May 18, 2010
remstart
color backdrop 0
#Constant Round_FadeIn 0
#Constant Round_Rotate 1
#Constant Round_FadeOut 2
global round as integer = 0
global rotationCounter as integer = 0
global alpha# as float = 0.0
global alphaspeed# as float = 0.2
global speed# as float = 0.2
CreateText(3,0,0,8,1,"BLAH",.1,2,1)
set object transparency 3,3
do
Select round
//Fade In
Case Round_FadeIn
//Increase the alpha-value
inc alpha#,alphaspeed#
set alpha mapping on 3,alpha#
//If faded in: next round
if alpha#>100.0
alpha#=100.0
round = Round_Rotate
endif
text 10,10,"Round_FadeIn: " + str$(alpha#) + "% Alpha"
Endcase
//Rotate
Case Round_Rotate
//rotate based on speed#
yrotate object 3, wrapvalue(object angle y(3) + speed#)
//if rotated nearly 360° increase the counter
if object angle y(3) >= ((360.0/speed#) - 1.0) * speed#
Inc rotationCounter
endif
//after 3 rotations: next round
if rotationCounter = 3 Then round = Round_FadeOut
text 10,10,"Round_Rotate: " + str$(rotationCounter) + " Rotations"
Endcase
//Fade out
Case Round_FadeOut
//Increase the alpha-value
dec alpha#,alphaspeed#
set alpha mapping on 3,alpha#
//If faded in: next round
if alpha#<0.0
alpha#=0.0
exit
endif
text 10,10,"Round_FadeOut: " + str$(alpha#) + "% Alpha"
Endcase
Endselect
LOOP
remend
Rem Project: loop
Rem Created: Tuesday, May 18, 2010
set display mode desktop width(),desktop height(),32,1
set window off
sync on
global Falling# as float
global TruckMesh=2
global loopmesh=1
global Speed# as float
global cameraon
cameraon=1
global gravityon
gravityon=0
global nx#
global ny#
global nz#
global coll
global test# as float
Rem ***** Main Source File *****
sync on
sync rate 60
autocam off
position camera -200,200,-200
`load loopy world
`load object "c:\temp\loop\loop.x",1
load object "loop.dbo",1
yrotate object 1,90
SC_setupObject 1,0,0
make object plane 4,5000,5000
xrotate object 4,270
`make a 'person'
global height as float
height=100
make object box 2,height/3,height,height/6
position object 2,-100,height/2,-100
REM NEW!!!
global camang as float
`for l= 1 to 100
`_load_bar(l)
`next l
global CameraDistance# as float
global AngleX# as float
global AngleY# as float
CameraDistance#=500
make object sphere 3,20
color object 3,rgb(255,0,0)
do
`set camera to follow object position x(TruckMesh),object position y(TruckMesh),object position z(TruckMesh),0,140,10,1,20
`set camera to object orientation TruckMesh
RotateCamera()
` hide object 2
` position camera object position x(2),object position y(2),object position z(2)
` rotate camera object angle x(2),object angle y(2),object angle z(2)
position object 3,object position x(2),object position y(2),object position z(2)
rotate object 3,object angle x(2),object angle y(2),object angle z(2)
move object up 3,20
move object 3,10
GoTruckGo()
text 10,10,"x:"+str$(object angle x(2))
text 10,30,"y:"+str$(object angle y(2))
text 10,50,"z:"+str$(object angle z(2))
text 10,70,"xpos:"+str$(object position x(2))
text 10,90,"ypos:"+str$(object position y(2))
text 10,110,"zpos:"+str$(object position z(2))
text 10,130,"nz#:"+str$(nx#)
text 10,150,"ny#:"+str$(ny#)
text 10,170,"nz#:"+str$(nz#)
text 10,190,"coll:"+str$(coll)+":"+"test:"+str$(test#)
sync
loop
function CreateText(obj,x#,y#,z#,fontid,strg$,depth#,quality,alignment)
D3D_StartText
D3D_Make_3DText obj,fontid,strg$,depth#,quality,alignment
position object obj,x#,y#,z#
D3D_EndText
endfunction
function GoTruckGo()
if Falling#=0.0
if upkey()=1
inc Speed#,0.5
endif
if downkey()=1
dec Speed#,0.5
endif
if leftkey()=1
turn object left 2,2
endif
if rightkey()=1
turn object right 2,2
endif
if spacekey()=1 then Speed#=0
endif
turn object right 2,0
if Falling#>1.0
xrotate object TruckMesh,0
dec Speed#
if Speed#<0.0 then Speed#=0.0
endif
T_oldx#=object position x(TruckMesh)
T_oldy#=object position y(TruckMesh)
T_oldz#=object position z(TruckMesh)
if Speed2#=0.0
move object TruckMesh,Speed#
else
move object TruckMesh,Speed2#
endif
Speed2#=0.0
Position object TruckMesh, object position x(TruckMesh), object position y(TruckMesh)-Falling#, object position z(TruckMesh)
inc Falling#,0.05
if object position y(TruckMesh)<50.0
Position object TruckMesh, object position x(TruckMesh),50, object position z(TruckMesh)
Falling#=0
endif
`*** need to determine the truck's "down vector" ****
move object down TruckMesh,50.0
x#=object position x(TruckMesh)
y#=object position y(TruckMesh)
z#=object position z(TruckMesh)
move object up TruckMesh,50.0
Collide#=SC_RayCast(loopmesh,T_oldx#,T_oldy#,T_oldz#,x#,y#,z#,0)
if Collide#>0
D#= SC_getCollisionDistance()
if D#>0.0
Falling#=0.0
y#=object angle y(TruckMesh)
if (abs(sc_getcollisionnormaly())-abs(cos(object angle x(TruckMesh))))>-0.707
yrotate object TruckMesh,0
if sc_getcollisionnormalz()<=0.0
xrotate object TruckMesh,-acos(sc_getcollisionnormaly())
else
xrotate object TruckMesh,acos(sc_getcollisionnormaly())+360
endif
yrotate object TruckMesh,y#
else
position object TruckMesh, T_oldx#,T_oldy#,T_oldz#
endif
move object TruckMesh,Speed#*2.0
x#=object position x(TruckMesh)
y#=object position y(TruckMesh)
z#=object position z(TruckMesh)
Collide2#=SC_RayCast(loopmesh,T_oldx#,T_oldy#,T_oldz#,x#,y#,z#,0)
if Collide2#>0
D#= SC_getCollisionDistance()
if D#<=Speed# then Speed2#=D# `this is so that on the next frame it won't go thru the wall
endif
move object TruckMesh,-Speed#*2.0
zrotate object TruckMesh,0
T_oldx#=object position x(TruckMesh)
T_oldy#=object position y(TruckMesh)
T_oldz#=object position z(TruckMesh)
move object down TruckMesh,50.0
x#=object position x(TruckMesh)
y#=object position y(TruckMesh)
z#=object position z(TruckMesh)
move object up TruckMesh,50.0
Collide2#=SC_RayCast(loopmesh,T_oldx#,T_oldy#,T_oldz#,x#,y#,z#,0)
if Collide2#>0
D#= SC_getCollisionDistance()
move object up TruckMesh,50.0-D#
endif
endif
endif
endfunction
Function _load_bar(percent)
horiz_offset = 0
vert_offset = 100
Ink 0,RGB(255,255,255)
Cls
Ink RGB(255,255,255),0
Line (Screen Width()/2 + horiz_offset - 152),(Screen Height()/2 + vert_offset - 17),(Screen Width()/2 + horiz_offset + 151),(Screen Height()/2 + vert_offset - 17)
Line (Screen Width()/2 + horiz_offset - 152),(Screen Height()/2 + vert_offset + 16),(Screen Width()/2 + horiz_offset + 151),(Screen Height()/2 + vert_offset + 16)
Line (Screen Width()/2 + horiz_offset - 152),(Screen Height()/2 + vert_offset - 17),(Screen Width()/2 + horiz_offset - 152),(Screen Height()/2 + vert_offset + 16)
Line (Screen Width()/2 + horiz_offset + 151),(Screen Height()/2 + vert_offset - 17),(Screen Width()/2 + horiz_offset + 151),(Screen Height()/2 + vert_offset + 16)
Ink RGB(255,255,255),0
Box (Screen Width()/2 + horiz_offset - 150),(Screen Height()/2 + vert_offset - 15),(Screen Width()/2 + horiz_offset - 150 + (percent*3)),(Screen Height()/2 + vert_offset + 15)
Ink rgb(0,255,0),0
Center Text (Screen Width()/2),(Screen Height()/2 - 50),"Please Wait"
Center Text (Screen Width()/2),(Screen Height()/2 - 35),"MonsterTruck test is loading..."
Center Text (Screen Width()/2),(Screen Height()/2 + 100),Str$(percent)+"% Loaded..."
Ink RGB(255,255,255),0
Sync
EndFunction
function RotateCamera()
MX# as float
MX#=MOUSEMOVEX()
MY# as float
MY#=MOUSEMOVEY()
AngleY#=wrapvalue(AngleY#+(MX#/5.0))
AngleX#=(AngleX#+(MY#/5.0))
if AngleX#>70.0 then AngleX#=70.0
if AngleX#<-70.0 then AngleX#=-70.0
MouseScroll=-mousemovez()
CameraDistance#=CameraDistance#+MouseScroll
if CameraDistance#>8000.0 then CameraDistance#=8000.0
if CameraDistance#<10.0 then CameraDistance#=10.0
position camera 0,300,0 `the lookat point
rotate camera AngleX#,AngleY#,0.0
move camera -CameraDistance#
endfunction
Sorry I am not as good as I thought I was with this. Rotations in DBP/DX are tricky at best and we are trying to do the hardest thing you can do with that system. If it's possible at all, I don't know how to do it with collisions as a base. Perhapse you can have better luck by making the player go around a pivot point in the center of the loop...?? Use the angle from that point to calculate the object's orientation.
Take a look at this code for instance:
set display mode desktop width(),desktop height(),32,1
set window off
sync on
make object box 2,2,10,1
global CameraDistance# as float
global AngleX# as float
global AngleY# as float
CameraDistance#=20
make object sphere 3,1
color object 3,rgb(255,0,0)
do
RotateCamera()
position object 3,object position x(2),object position y(2),object position z(2)
rotate object 3,object angle x(2),object angle y(2),object angle z(2)
move object up 3,5
move object 3,1
if upkey()=1 then pitch object up 2,3
if downkey()=1 then pitch object down 2,3
if leftkey()=1 then turn object left 2,3
if rightkey()=1 then turn object right 2,3
text 10,10,"x:"+str$(object angle x(2))
text 10,30,"y:"+str$(object angle y(2))
text 10,50,"z:"+str$(object angle z(2))
text 10,70,"xpos:"+str$(object position x(2))
text 10,90,"ypos:"+str$(object position y(2))
text 10,110,"zpos:"+str$(object position z(2))
sync
loop
function RotateCamera()
MX# as float
MX#=MOUSEMOVEX()
MY# as float
MY#=MOUSEMOVEY()
AngleY#=wrapvalue(AngleY#+(MX#/5.0))
AngleX#=(AngleX#+(MY#/5.0))
if AngleX#>70.0 then AngleX#=70.0
if AngleX#<-70.0 then AngleX#=-70.0
MouseScroll=-mousemovez()
CameraDistance#=CameraDistance#+MouseScroll
if CameraDistance#>8000.0 then CameraDistance#=8000.0
if CameraDistance#<10.0 then CameraDistance#=10.0
position camera 0,0,0 `the lookat point
rotate camera AngleX#,AngleY#,0.0
move camera -CameraDistance#
endfunction
No matter which direction it faces the "turn object" commands are all local to it's CURRENT orientation. Even the "pitch object" commands are local. Perhapse you can figure a way to make it work only using pitch,turn, and roll commands, but I couldn't get it to work right when it took a collision calculation...
I'm all out of ideas here. Once again, I'm sorry I couldn't get it to work perfectly. I have other projects I've put on the back-burner to help you and now I have to get back to them..... Good Luck, friend.
The fastest code is the code never written.