Upon key release?

Blitz3D Forums/Blitz3D Beginners Area/Upon key release?

Sph!nx(Posted 2008) [#1]
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!


josk(Posted 2008) [#2]
Not great on 3D code but have you tried to Position the player before changing the entity radius.


blade007(Posted 2008) [#3]
Well there's a way to detect if a key has been released for an instant.
While Not KeyDown(1)
    If KeyDown(29)
           ;Stuff goes here.
           CtrlPress = True
   else
         If CtrlPress = True
                ;Ctrl has been Released!
                ;Stuff goes here.
                CtrlPress = False ;Now turn off the trigger
         Endif
   Endif
Wend



Sph!nx(Posted 2008) [#4]
Thanks a lot!


Edit: Works like a charm!