Here's a sample of strafing and jumping (though I've not got that working quite right yet):
#constant player_object = 100
#constant bullet_velocity = 1000
type TBullet
id
start
endtype
global nObjectIndex = 0
global nBulletIndex = 1000
global fspeed as float = 5.0
global fturn as float = 0.03
global oldcamx as float
global oldcamy as float
global camx as float
global camy as float
randomize timer()
phy start
autocam off
phy set gravity 0, -9.8, 0
sync on
sync rate 60
backdrop off
set display mode 1024, 768, 32
set camera range 0.5, 35000
hide mouse
rem ground
ground = GetNextIndex()
make object plain ground, 30000, 30000
color object ground, rgb(20, 120, 20)
xrotate object ground, -90
phy make rigid body static box ground
rem a few boxes
for i = 1 to 20
boxes = GetNextIndex()
make object box boxes, 20, 20, 20
position object boxes, 30 * i, 60, 0
color object boxes, rgb(64 + rnd(127), 64 + rnd(127), 64 + rnd(127))
phy make rigid body dynamic box boxes
phy set rigid body mass boxes, 1000.0
next
rem Player controller
make object box player_object, 100, 100, -200
phy make box character controller player_object, 100, 100, -200, 10, 50, 10, 1, 16, 45
hide object player_object
rem Light inside
light_object = GetNextIndex()
make light light_object
set point light light_object, 0, 600, 0
vec = make vector3( bullet_velocity )
start = 0
dim bullets() as TBullet
empty array bullets()
do
now = timer()
text 10, 20, "FPS: " + STR$(screen fps())
text 10, 40, "Camera: " + STR$(object position x(player_object), 2) + " " + STR$(object position y(player_object), 2) + " " + STR$(object position z(player_object), 2)
text 10, 60, "Bullets: " + str$(array count(bullets()))
array index to top bullets()
while array index valid(bullets())
if now - bullets().start > 10000
phy delete rigid body bullets().id
delete object bullets().id
array delete element bullets()
else
next array index bullets()
endif
endwhile
position mouse 512, 384
position camera object position x(player_object), object position y(player_object) + 20, object position z(player_object)
rotate camera object angle x(player_object), object angle y(player_object), object angle z(player_object)
remstart
position listener object position x(player_object), object position y(player_object) + 20, object position z(player_object)
rotate listener object angle x(player_object), object angle y(player_object), object angle z(player_object)
remend
oldcamx = camx
oldcamy = camy
camx = wrapvalue( camx + mousemovey() * 0.4 )
camy = wrapvalue( camy + mousemovex() * 0.4 )
xrotate camera 0, curveangle( camx, oldcamx, 24 )
yrotate object player_object, curveangle( camy, oldcamy, 24 )
key = false
if upkey()
key = true
phy move character controller player_object, 200.0
endif
if downkey()
key = true
phy move character controller player_object, -200.0
endif
if leftkey()
key = 1
camy = wrapvalue( camy - 90 )
yrotate object player_object, camy
phy move character controller player_object, 200.0
camy = wrapvalue( camy + 90 )
yrotate object player_object, camy
endif
if rightkey()
key = 1
camy = wrapvalue( camy + 90 )
yrotate object player_object, camy
phy move character controller player_object, 200.0
camy = wrapvalue( camy - 90 )
yrotate object player_object, camy
endif
if spacekey()
key = 1
camx = wrapvalue( camx - 90 )
xrotate object player_object, camx
phy move character controller player_object, 200.0
camx = wrapvalue( camx + 90 )
xrotate object player_object, camx
endif
if key = false
phy move character controller player_object, 0.0
endif
if mouseclick() = 1
if now - start > 300
x# = object position x(player_object)
y# = object position y(player_object) + 20
z# = object position z(player_object)
bullet = GetBulletIndex()
make object sphere bullet, 10
color object bullet, rgb(64 + rnd(127), 64 + rnd(127), 64 + rnd(127))
position object bullet, x#, y#, z#
rotate object bullet, camera angle x(), camera angle y(), camera angle z()
move object bullet, 20
x# = object position x(bullet) - x#
y# = object position y(bullet) - y#
z# = object position z(bullet) - z#
set vector3 bullet_velocity, x#, y#, z#
normalize vector3 bullet_velocity, bullet_velocity
x# = x vector3(bullet_velocity)
y# = y vector3(bullet_velocity)
z# = z vector3(bullet_velocity)
phy make rigid body dynamic sphere bullet
phy set rigid body mass bullet, 100
phy set rigid body linear velocity bullet, x# * 1000, y# * 1000, z# * 1000
array insert at bottom bullets()
bullets().id = bullet
bullets().start = now
start = now
endif
endif
phy update
sync
loop
end
function GetNextIndex()
inc nObjectIndex
endfunction nObjectIndex
function GetBulletIndex()
inc nBulletIndex
if nBulletIndex > 1100 then nBulletIndex = 1000
endfunction nBulletIndex
What's wrong with the jumping code is it actually moves straight up - hardly 'jumping'. Then, let go of the spacebar and it drifts back down to the ground - as soon as you move, you shoot back down to the ground. It's this behaviour I haven't quite figured out yet.
"Reality Bites"