Posted: 23rd Dec 2002 10:27
heres the source code I used for trying to make the ship move besides using the MOVE command.. the problem is, the ship it not movie where its supposed to be. so if I turn my ship 180 degrees(facing me), its still moving away from me rather than moving towards me. and also the ship moves a billion different directions rather than its supposed to go when its facing that way. This is the modified version of the maths phsyics example that came with DB.

+ Code Snippet
rem Load and animate your object (backdrop is auto-activated)
load object "strider.3ds",1
xrotate object 1,270
yrotate object 1,180
fix object pivot 1

rem Activate manual sync
sync on

rem Begin main loop
while mouseclick()=0
rem Control variables with the cursor keys
if upkey()=1 then dx#=newxvalue(dx#, angle#, 3.0) : dz#=newzvalue(dz#, rangle#, 3.0):dy#=newyvalue(dy#,pangle#,3.0)
if downkey()=1 then dx#=newxvalue(dx#, angle#, -3.0) : dz#=newzvalue(dz#, rangle#, -3.0):dy#=newyvalue(dy#,pangle#,-3.0)
if leftkey()=1 then angle#=wrapvalue(angle#-10)
if rightkey()=1 then angle#=wrapvalue(angle#+10)
if inkey$()="w" then pangle#=wrapvalue(pangle#+10)
if inkey$()="s" then pangle#=wrapvalue(pangle#-10)
if inkey$()="a" then rangle#=wrapvalue(rangle#+10)
if inkey$()="d" then rangle#=wrapvalue(rangle#-10)

rem You can curve values creating a smooth transition of position
x#=curvevalue(dx#, x#, 10.0)
y#=curvevalue(dy#, y#, 10.0)
z#=curvevalue(dz#, z#, 10.0)

rem You can curve angles creating smooth transition of rotation
ca#=curveangle(angle#, ca#, 5.0)
pa#=curveangle(pangle#, pa#, 5.0)
ra#=curveangle(rangle#, ra#, 5.0)

rem Update the object with these new values
position object 1,x#,y#,z#
yrotate object 1,ca#
xrotate object 1,pa#
zrotate object 1,ra#

rem Update Screen
sync

rem End main loop
endwhile

rem End the program
end
Posted: 23rd Dec 2002 10:58
Where is the physics in that? I made a flight sim, thats about 100+ lines, and, I dont think I used any physics unless you want to include pitch roll and yaw. I need to figure out how to do a landing script though :-(
Posted: 23rd Dec 2002 17:49
Well this is for space though. I never botherd making one for the air phsyics.
Posted: 23rd Dec 2002 21:51
Oh, ok. I could probably think up something for that. What kind of DarkBASIC do you have. I have pro
Posted: 24th Dec 2002 0:47
I have DBV1.
Posted: 24th Dec 2002 1:13
Here's a nice spaceflight thing I made:

+ Code Snippet
rem Space Flight Code, by The Darthster!
rem Initialisation
sync on
sync rate 30
hide mouse
autocam off

rem Make a terrain to fly over
make matrix 1,10000,10000,50,50

rem Set up initial positions and angles
x#=5000
y#=200
z#=5000
theta#=0
phi#=0
thruststep#=0.1

rem Set up bullets
dim shot#(10,10)
for i=0 to 9
make object sphere i+1,5
next i

do
rem Mouseclicks control speed
if mouseclick()=1 then thrust#=thrust#+thruststep#
if mouseclick()=2 then thrust#=thrust#-thruststep#

rem Now the joystick button controls speed
`if joystick fire a()=1 then thrust#=thrust#+thruststep#


if keystate(17)=1 then yaxisstrafe#=yaxisstrafe#-thruststep#
if keystate(30)=1 then xaxisstrafe#=xaxisstrafe#-thruststep#
if keystate(31)=1 then yaxisstrafe#=yaxisstrafe#+thruststep#
if keystate(32)=1 then xaxisstrafe#=xaxisstrafe#+thruststep#

rem Shooting
rem Putting in a firing delay
if mouseclick()=4 and shotrecently#=0
shotrecently#=4
for i=0 to 9
rem If the bullet is 'dead' then create a new one
if shot#(i,0)=0
rem Alive
shot#(i,0)=1
rem Current position
shot#(i,1)=x#
shot#(i,2)=y#
shot#(i,3)=z#
rem Current velocities plus velocities provided by the gun
shot#(i,4)=xvel#+(sin(theta#)*cos(phi#)*20)
shot#(i,5)=yvel#-(sin(phi#)*20)
shot#(i,6)=zvel#+(cos(theta#)*cos(phi#)*20)
rem Angle
shot#(i,7)=theta#
shot#(i,8)=phi#
rem Life
shot#(i,9)=30
show object i+1
exit
endif
next i
endif

if shotrecently#>0 then shotrecently#=shotrecently#-1

rem Update the bullets
for i=0 to 9
rem If the bullet is 'alive' then move it by it's velocity
if shot#(i,0)=1
shot#(i,1)=shot#(i,1)+shot#(i,4)
shot#(i,2)=shot#(i,2)+shot#(i,5)
shot#(i,3)=shot#(i,3)+shot#(i,6)
position object i+1,shot#(i,1),shot#(i,2),shot#(i,3)
shot#(i,9)=shot#(i,9)-1
rem If it's just run out of 'life' then 'kill' it and make
rem it available for use again
if shot#(i,9)=0
hide object i+1
shot#(i,0)=0
endif
endif
next i

rem Mouse movements control angles
theta#=curveangle(theta#+mousemovex(),theta#,7)
phi#=curveangle(phi#+mousemovey(),phi#,7)

`theta#=wrapvalue(theta#+mousemovex())
`phi#=wrapvalue(phi#+mousemovey())

rem Joystick controls angles
`theta#=wrapvalue(theta#+(joystick x()*0.005))
`phi#=wrapvalue(phi#-(joystick y()*0.005))


rem Decay the thrust so you don't go really fast
thrust#=thrust#*0.9
xaxisstrafe#=xaxisstrafe#*0.9
yaxisstrafe#=yaxisstrafe#*0.9

rem Accelerate the velocities (this took ages to work out)
xvel#=xvel#+(sin(theta#)*cos(phi#)*thrust#)
yvel#=yvel#-(sin(phi#)*thrust#)
zvel#=zvel#+(cos(theta#)*cos(phi#)*thrust#)

xvel#=xvel#+(sin(theta#+90)*xaxisstrafe#)
zvel#=zvel#+(cos(theta#+90)*xaxisstrafe#)

xvel#=xvel#+(sin(theta#)*cos(phi#+90)*yaxisstrafe#)
yvel#=yvel#-(sin(phi#+90)*yaxisstrafe#)
zvel#=zvel#+(cos(theta#)*cos(phi#+90)*yaxisstrafe#)

rem Some friction to stop you going too fast
xvel#=xvel#*0.99
yvel#=yvel#*0.99
zvel#=zvel#*0.99

rem Simple velocity
x#=x#+xvel#
y#=y#+yvel#
z#=z#+zvel#

rem Screen display
text 0,0,"X velocity:"
text 0,20,"Y velocity:"
text 0,40,"Z velocity:"
text 0,60,"Theta:"
text 0,80,"Phi:"
text 0,100,"Thrust:"
text 100,0,str$(xvel#)
text 100,20,str$(yvel#)
text 100,40,str$(zvel#)
text 100,60,str$(theta#)
text 100,80,str$(phi#)
text 100,100,str$(thrust#)

rem Rotate and position the camera
position camera x#,y#,z#
yrotate camera theta#
xrotate camera phi#
sync
loop


Left click to thrust, middle click to fire, wasd to strafe.
Posted: 31st Dec 2002 18:49
aah cool.. Thanks.. I'll save this for later use.