Hello again! Besides making a game with reading waypoint maps traffic lights etc. from an X file. I am currently making a different game on the side, to clear my mind a bit.
I'm using Sparkys DLL for my collision.
I have never done this before, player movement. I've always used the Sparkys DLL example and edited it to my needs.
But now I'm writing my own piece of movement code, and I need some feedback!
All is working OK, except that my player sometimes gets stuck when jumping. This happens at the very start of the game, and it happens when I walk up the pretty stair I've created.
Here is my code :
Function PlayerMovement()
Player.OldX = Object Position X(Player.ID)
Player.OldY = Object Position Y(Player.ID)
Player.OldZ = Object Position Z(Player.ID)
ObjAngX# = Object Angle x(Player.ID)
ObjAngY# = Object Angle y(Player.ID)
ObjAngZ# = Object Angle z(Player.ID)
If Leftkey()=1 Or Keystate(30) = 1
Player.X = Newxvalue(Player.X,Wrapvalue(Camera Angle Y(0)-90),Player.Speed)
Player.Z = Newzvalue(Player.Z,Wrapvalue(Camera Angle Y(0)-90),Player.Speed)
Endif
If Rightkey()=1 Or Keystate(32) = 1
Player.X = Newxvalue(Player.X,Wrapvalue(Camera Angle Y(0)+90),Player.Speed)
Player.Z = Newzvalue(Player.Z,Wrapvalue(Camera Angle Y(0)+90),Player.Speed)
Endif
If Upkey() = 1 Or Keystate(17) = 1
Player.X = Newxvalue(Player.X,Camera Angle Y(0),Player.Speed)
Player.Z = Newzvalue(Player.Z,Camera Angle Y(0),Player.Speed)
Endif
If Downkey() = 1 Or Keystate(31) = 1
Player.X = Newxvalue(Player.X,Camera Angle Y(0),-Player.Speed)
Player.Z = Newzvalue(Player.Z,Camera Angle Y(0),-Player.Speed)
Endif
yRotate Object Player.ID,ObjAngY#+mousemovex()/3.0
xRotate Object Player.ID,ObjAngX#+MouseMoveY()/3.0
If ObjAngX# > 50 : ObjAngX# = 50 : Endif
If ObjAngX# < -50 : ObjAngX# = -50 : Endif
Yrotate Camera ObjAngY#
Xrotate Camera ObjAngX#
Collide = Sc_Spherecastgroup(0,Player.OldX,Player.OldY,Player.OldZ,Player.X,Player.Y,Player.Z,Player.Size,0)
If Collide <> 0
Player.X = SC_GetCollisionSlideX()
Player.Y = SC_GetCollisionSlideY()
Player.Z = SC_GetCollisionSlideZ()
Endif
Ground_Collide = SC_Raycast(0,Player.X,Player.Y,Player.Z,Player.X,Player.Y-20,Player.Z,0)
If Ground_Collide <> 0
Player.Ground = 1
Player.Gravity = 0.3
Else
Player.Ground = 0
Inc Player.Gravity,0.1
Endif
If Player.Ground = 1
Player.Y = Player.Y
If Keys(57,1) = 1 And Player.Ground = 1
Player.Jump = 1
Else
Player.Jump = 0
Endif
Else
Dec Player.Y,Player.Gravity
Endif
If Player.Jump = 1
NewYpos# = Player.Y + 40
Inc Player.Y,2
Endif
`If Player.Y > NewYpos#-2
` Player.Jump = 0
`Endif
If Player.Gravity > 5
Player.Gravity = 5
Endif
If Player.Y < -1000
Player.x = 0
Player.y = 20
Player.z = 0
Endif
Print "Ground_Collide ";Ground_Collide
Print "Player.Ground ";Player.Ground
Print "Player.Jump ";Player.Jump
Print "Player.Gravity ";Player.Gravity
Position Object Player.ID, Player.X,Player.Y,Player.Z
Position Camera Object Position X(Player.ID),Object Position Y(Player.ID),Object Position Z(Player.ID)
Sc_UpdateObject Player.ID
EndFunction
And I've attached the game.
It acts as if my collision check from the player is still inside the stair. When you press space a couple of times you'll notice it's "out" of the collision and acts normal again.
Any other feedback on the code will be accepted as well!