I've been fooling around with someone's car physics sample trying to create bouncing collision of some sort.
here's the code: you can simply plug it in and it should work, however, im having trouble getting the car to have any collision detection when driving in reverse?
any ideas? on that?
`fuzz Setup
Sync on : Sync rate 60
Set display mode 1024,768,32 : hide mouse
Autocam off : set camera range 1,0x7fffffff
`Player data
type player
x as float
y as float
z as float
ay as float
v as float
u as float
d as float
t as float
a as float
m as float
g as float
w as float
f as float
ft as float
mu as float
ew as float
ek as float
av as float
cl as float
tr as float
wha as float
endtype
plr as player
`Configure
speed#=200.0
turn#=90.0
trac#=0.95
mass#=100.0
plr.m=mass#
plr.g=0.98
plr.w=plr.m*plr.g
plr.ft=trac#
plr.cl=50
`Create player
make object box 1,50,20,plr.cl*2
set object collision to boxes 1
make object box 2,1000,40,10000
position object 2, 5000,-20,5000
zrotate object 2,90
set object collision to spheres 2
`Create world
Make matrix 1,20000,20000,40,40
position matrix 1,0 ,0,0
`**Main Loop**
Do
ox#=Object Position x(1)
oy#=Object Position y(1)
oz#=Object Position z(1)
`Control keys
if upkey()=1 or joystick Y ( ) < -600 then up=1 else up=0
if downkey()=1 or joystick Y ( ) > 600 then down=1 else down=0
if leftkey()=1 or joystick X ( ) < -600 then left=1 else left=0
if rightkey()=1 or joystick X ( ) > 600 then right=1 else right=0
`If key pressed.
if up=1
if x<=0
plr.f=speed#
plr.d=plr.d+plr.v
else
plr.f=speed#-9000
plr.d=plr.d+plr.v
endif
endif
if down=1
if x<=0
plr.f=speed# * -1
plr.d=plr.d+plr.v
else
plr.v=0
plr.f=speed# - 9000
plr.d=plr.d+plr.v
endif
endif
if up=0 and down=0 then plr.f=0 : plr.d=0
if left=1
plr.wha=-turn#
endif
if right=1
plr.wha=turn#
endif
if left=0 and right=0 then plr.wha=0.0
`Relationships
plr.a=plr.f/plr.m :`Acceleration = force / mass
plr.v=plr.v+plr.a :`Speed = speed + acceleration
plr.v=plr.v*plr.ft :`Speed = speed x traction
plr.tr=plr.cl/sin(plr.wha) :`Turning radius = axle distance / sin ( wheel angle )
plr.av=plr.v/plr.tr :`Angular velocity = speed / turning radius
plr.ay=wrapvalue(plr.ay+plr.av) :`Angle = angle + angular velocity
plr.ew=plr.f*plr.d :`Work done = force x distance traveled
plr.ek=(0.5*plr.m)*(plr.v)^2 :`Kinetic Energy = 1/2 mass x (vxv)
`Update player
`Calculate new coords
plr.x=plr.x+sin(plr.ay)*plr.v
plr.z=plr.z+cos(plr.ay)*plr.v
position object 1,plr.x,plr.y,plr.z
yrotate object 1,plr.ay
x= Object collision(1,0)
if x<> 0
text 50, 30, "HIT!!!"
If Object collision(1,0)<>0
plr.v=plr.v/1.03
position object 1, plr.x,oy#,oz#
If Object collision(1,0)<>0
plr.v=plr.v/1.03
position object 1, ox#,oy#,plr.z
If Object collision(1,0)<>0
plr.v=0
position object 1, ox#,oy#,plr.z
endif
endif
endif
endif
`Camera
if (plr.x <= 20000 and plr.x >= 0 and plr.z <= 20000 and plr.z >= 0 and x<=0)
ca#=curveangle(plr.ay,ca#,20.0)
cx#=plr.x-sin(ca#)*600
cz#=plr.z-cos(ca#)*600
cy#=plr.y+300.0
position camera cx#,cy#,cz#
point camera plr.x,plr.y,plr.z
endif
if (plr.x >= 20000)
text 600,20, "first"
position object 1, 20000, plr.y, plr.z
position camera 20000,500,plr.z
point camera 20000, plr.y, plr.z
endif
if (plr.z >= 20000)
text 600,50, "second"
position object 1, plr.x, plr.y, 20000
position camera plr.x,500,20000
point camera plr.x, plr.y, 20000
endif
if (plr.x <= 0)
text 600,80, "third"
position object 1, 0, plr.y, plr.z
position camera 0, 500, plr.z
point camera 0, plr.y, plr.z
endif
if (plr.z <= 0)
text 600,120, "forth"
position object 1, plr.x, plr.y, 0
position camera plr.x,500,0
point camera plr.x, plr.y, 0
endif
if plr.z >=20000 && plr.x <=0
position object 1,0,plr.y,20000
position camera 0,500,20000
text 600, 150,"third-second"
endif
if plr.x <=0 && plr.z <=0
position object 1,0,plr.y,0
position camera 0,500,0
text 600, 150,"third-forth"
endif
if plr.x >=20000 && plr.z >=20000
position object 1,20000,plr.y,20000
position camera 20000,500,20000
text 600, 180,"first-second"
endif
if plr.x >=20000 && plr.z <=0
position object 1,20000,plr.y,0
position camera 20000,500,0
text 600, 210,"first-forth"
endif
`**End Loop**
Sync
Loop
www.total-classics.com