Hi "Again!" peeps at TGC
EDIT!: I got help with this problem, thanks to the person(s) below this post(s) - I got a new problem, wich is posted below
Okay. I made a very simple WSAD + Mouse look test game with the help of some snippets. (Needed something fast for this).
This is for testing some player animations and collision.
I just got one problem (atm.)
When i compile, my player (Object 2) stays under the ground, moves and collides. But it still wont walk on the ground.
I have attached a compiled exe, the test animation and the map.
And here is my code. Feel free to take a look at it
sync on
sync rate 60
hide mouse
autocam off
radius# = 7.0
gravity# = -0.1
slope# = 0.5
ground = 1
jumptimer = 0
gosub makeLevel
gosub makePlayer
do
gosub Animation
gosub MovePlayer
`Change to 3rd person View
if inkey$()="v" and vtimer<timer() then vtimer = timer()+300 : view = 1-view
positionCameraToObject(2,view)
`Just some random text to show me position etc.
text 0,20,"x rot: "+str$(object angle x(2))
text 0,40,"y rot: "+str$(object angle y(2))
text 0,60,"z rot: "+str$(object angle z(2))
text 0,80,"FPS: "+str$(screen fps())
text 0,100,"Touching Ground: "+str$(ground)
text 0,120,"x = "+str$(object position x(2))
text 0,140,"y = "+str$(object position y(2))
text 0,160,"z = "+str$(object position z(2))
if inkey$() = "q" then end
if shiftkey() = 1 then position object 2,0,50,0
sync
loop
makeLevel:
load object "map.x",1
sc_setupComplexObject 1,1,2
return
makePlayer:
load object "Anim01.x",2
position object 2,0,500,0
Scale object 2,100,100,100
sc_setupObject 2,0,1
return
Animation:
if keystate(17) = 1
if walking = 0
loop object 2, 1, 40
walking = 1
endif
else
stop object 2
walking = 0
endif
movePlayer:
`Rotate the player with the mouse
yrotate object 2,object angle y(2)+mousemovex()/3.0
xrotate object 2,object angle x(2)+mousemovey()/3.0
oldx# = object position x(2)
oldy# = object position y(2)
oldz# = object position z(2)
`Movement and gravity
angy# = object angle y(2)
vx# = 0
vz# = 0
if vy#=0 and jumptimer=0 then vy# = vy# + 10*gravity# else vy# = vy# + gravity#
if keystate(32)=1 then vx# = vx# + cos(angy#) : vz# = vz# - sin(angy#)
if keystate(30)=1 then vx# = vx# - cos(angy#) : vz# = vz# + sin(angy#)
if keystate(31)=1 then vx# = vx# - sin(angy#) : vz# = vz# - cos(angy#)
if keystate(17)=1 then vx# = vx# + sin(angy#) : vz# = vz# + cos(angy#)
`Only jump if = on ground, and a certain time after last jump
if ground=1
if spacekey()=1 and jumptimer=0 then vy# = vy# + 3.0 : jumptimer = 20
endif
x# = oldx#+vx#
y# = oldy#+vy#
z# = oldz#+vz#
collide = sc_SphereCastGroup(1,oldx#,oldy#,oldz#,oldx#,oldy#+vy#,oldz#,radius#,0)
if collide>0
ny# = sc_getCollisionNormalY()
if abs(ny#)>slope#
`FLAT, stick
oldy# = sc_getStaticCollisionY()
else
`STEEP, slide
x# = x# - oldx# : z# = z# - oldz#
oldx# = sc_getCollisionSlideX()
oldy# = sc_getCollisionSlideY()
oldz# = sc_getCollisionSlideZ()
x# = x# + oldx# : z# = z# + oldz#
endif
if ny#>slope#
`Only on ground if standing on flat ground
ground = 1
vy# = 0
else
ground = 0
`If player has hit a flat ceiling then stop vy# movement
if ny#<-slope# then vy# = gravity#
endif
else
`Nothing below player, not on ground, add vertical speed to player
oldy# = oldy# + vy#
ground = 0
endif
if ground = 1 and jumptimer>0 then dec jumptimer
collide = sc_SphereSlideGroup(1,oldx#,oldy#,oldz#,x#,oldy#,z#,radius#,0)
if collide>0
`If hit, reposition player, halt movement vector
x# = sc_getCollisionSlideX()
oldy# = sc_getCollisionSlideY()
z# = sc_getCollisionSlideZ()
vx# = 0
vz# = 0
endif
`Position the player
position object 2,x#,oldy#,z#
return
function positionCameraToObject(obj,thirdPerson)
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)
if thirdPerson=1
pitch camera down 10
move camera -700
endif
endfunction
if memblock exist(1) then delete memblock 1
--------------------------------------
NewBie - Coding? Damn..