X/Y/Z Collision

Blitz3D Forums/Blitz3D Beginners Area/X/Y/Z Collision

Or you could use the existing collision information to find the average collision normal in the Y direction. If it's > 0 the normal points up and your standing on something. Like so :

If KeyHit(57)

	If EntityCollided(player,world_col)
	
		If CollNY( player ) > 0

			While Player_velocityY =< 2		
				
				Player_velocityY = Player_velocityY + Gravity
		
			Wend
			
		EndIf
		
	EndIf
	
EndIf


Function CollNY#( Entity )

	Ny# = 0
	cc = CountCollisions( Entity )

	For c = 1 To cc
		Ny# = Ny# + CollisionNY( Entity , c )
	Next
	
	Return ( Ny / cc )
	
End Function		


Even then, your jumping code doesn't look right. You want to be adding an acceleration ( greater than gravity ) to the velocity in the upward direction if jump is pressed and you are on the ground. Also, apply gravity whenever you are not on the ground.

You'd need to play with the gravity and jumpacceleration variables ..

Const Gravity# = 9.81
Const JumpAcceleration# = 25.0

.
.
.
.

OnGround = ( CollNY( player ) > 0 )

If OnGround
	If KeyHit(57)
		Player_velocityY = Player_velocityY + JumpAcceleration
	EndIf
Else
	Player_velocityY = Player_velocityY - Gravity
EndIf



Stevie