Thanks dudes.
@Terabyte
Not sure its that good, but I'll be using it as an alternative anyhow. Cheers
@Ilya
Do you mean NG's DLL, or this code?
Feel free to use this code anyway.
@Everyone
New code:
set display mode 800,600,16
sync on
sync rate 60
autocam off
Set camera range 1,20000
hide mouse
set normalization on
backdrop on
color backdrop RGB(98,98,255)
rem Make normal light
set ambient light 30
rem Make shadow light
make light 1
position light 1,250,100,250
color light 1,225,205,105
set light range 1,10000
fog on : fog distance 50000 : fog color RGB(100,100,100)
rem inilalize player origin
X#=0
Z#=0
Y#=0
****************************LEVEL GOES HERE************************
load object "LEVEL HERE.X/.3DS",7
position object 7,0,-200,0
scale object 7,100,100,100
set object texture 7,0,1
Set object collision to polygons 7
rem make players wall collision
make object cube 10,70
Set object collision to polygons 10
hide object 10
rem create player ground collision
make object cube 4,65
set object collision to polygons 4
hide object 4
player_speedz1=0
Rem Main loopy loop
Do
set cursor 10,10
print screen fps()
oldcAY# = cAY#
oldcAX# = cAX#
cAY# = WrapValue(cAY#+MousemoveX()*0.2)
cAX# = WrapValue(cAX#+MousemoveY()*0.2)
caZ# = Camera angle Z()
Rem input for the players wall collision
if KEYSTATE(17)
XTest# = Newxvalue(X#,cAY#,speed)
ZTest# = Newzvalue(Z#,cAY#,speed)
gosub SlidingCollision
else
if KEYSTATE(31)
XTest# = Newxvalue(X#,Wrapvalue(cAY#-180),speed)
ZTest# = Newzvalue(Z#,Wrapvalue(cAY#-180),speed)
gosub SlidingCollision
Endif
Endif
if KEYSTATE(30)
XTest# = Newxvalue(X#,Wrapvalue(cAY#-90),speed)
ZTest# = Newzvalue(Z#,Wrapvalue(cAY#-90),speed)
gosub SlidingCollision
else
if KEYSTATE(32)
XTest# = Newxvalue(X#,Wrapvalue(cAY#+90),speed)
ZTest# = Newzvalue(Z#,Wrapvalue(cAY#+90),speed)
gosub SlidingCollision
Endif
Endif
Rem Rotate camera with mouse movement
YRotate camera CurveAngle(cAY#,oldcAY#,24)
XRotate camera CurveAngle(cAX#,oldcAX#,24)
rem position camera at the position of the players sliding sphere
Position Camera X#-25,Object position y(10)+20,Z#
`jump
if spacekey()=1
position object 10,Object position x(10),Object position y(10)+height,Object position z(10)
height=height-1
else
height=20
endif
if height=<0
height=0
endif
`crouch
if controlkey()=1
crouch=crouch+5
else
crouch=crouch-5
endif
if crouch=>50
crouch=50
endif
if crouch=<0
crouch=0
endif
`walk
if KEYSTATE(42) or controlkey()=1
speed=10
else
speed=20
endif
`goto gravity
gosub gravity
gosub hitroof
Sync
Loop
Rem Heres the magic
SlidingCollision:
position object 10,XTest#,Object position y(10),Z#
if object collision(7,10) = 0 then X# = XTest#
position object 10,X#,Object position y(10),ZTest#
if object collision(7,10) = 0 then Z# = ZTest#
return
Gravity:
rem gravity
position object 4,X#,Object position y(10)-63+crouch,Z#
if Object collision(7,4)>0
ondeck=1
else
ondeck=0
if player_speedz1=>0
player_speedz1=0
endif
player_speedz1=player_speedz1-1
position object 10,Object position x(10),Object position y(10)+player_speedz1,Object position z(10)
endif
position object 4,X#,Object position y(10)-64+crouch,Z#
if Object collision(7,4)>0
if player_speedz1=<-0
player_speedz1=0
endif
player_speedz1=player_speedz1+1
position object 10,Object position x(10),Object position y(10)+player_speedz1,Object position z(10)
endif
if player_speedz1=>50
player_speedz1=50
endif
if player_speedz1=<-50
player_speedz1=-50
endif
return
hitroof:
position object 4,X#,Object position y(10)+50,Z#
if Object collision(7,4)>0
height=0
if player_speedz1=>0
player_speedz1=0
endif
endif
return
The controls are the standard FPS ones. WAS and D to run around, space to jump, control to crouch and shift to walk.
@Oliver
Your not going to like it!
Update:
I'm in the process of revising this code further now. This time, there will be no annoying bobbing up and down while walking up hills. That portion of the code is complete, but I will also be adding more features.
Check back for further updates of my WIP FPS engine.
Infra-Dark
Bring the 20 liners back!
#coding, like coding, but with a #