I have made this 'duck movement' code for my FPS engine. This code makes it so the camera gets lowered and the player collision radius gets shrunken so he can crawl through smaller spaces.
Here is the code:
; Duck Code
If EntityCollided(player,world_col)
If KeyDown(29) Then
PositionEntity playercam,0,20,0
EntityRadius player,16,25 ; player collision radius
Else
EntityRadius player,16,40 ; player collision radius
PositionEntity playercam,0,36,0
EndIf
EndIf
It works, well sort of. I can make the player duck, but when I stand up (release the CTRL key) the player collision becomes bigger and clips through the terrain, so the player falls through because normal gravity resumes. This is not good.
So I figured, upon release of the ctrl key, I position the player a bit up (in its current location on the map) and the collision can become bigger, without going through the terrain collision.
I tried a lot of thing with many strange outcomes. Can anybody help me? I basically need a way to position the player pivot, on its current location on the map, after the CTRL key has been released.
Thanks a lot!
|