Jumping

Blitz3D Forums/Blitz3D Programming/Jumping

Could anyone tell me how to create a jump effect? Thanks.....

This is typed straight into the codebox, but it might work :)

graphics3d 640,480,0,2
setbuffer backbuffer()

player = createcube()

camera = createcamera()
positionentity camera,0,3,-10

player_y# = 0.0
player_speed_y# = 0.0

gravity# = -0.1

while not keyhit(1)
if keyhit(57)
player_speed_y = 1.0
endif

player_y = player_y + player_speed_y
player_speed_y = player_speed_y + gravity

if player_y<0.0
player_y = 0.0
player_speed_y = 0.0
endif

positionentity player,0,player_y,0

renderworld

text 0,0,"Press Space to jump"

flip
wend
end


thanks :)

replace

if keyhit(57)
player_speed_y = 1.0
endif

-with-

If player_y#=0
If KeyHit(57)
player_speed_y = 1.0
EndIf
EndIf

it doesnt allow you to jump while your in the air, but it would only be useful if ur level is flat...which i think urs is "no enemies"? for ur cylinder shooter?

yes....it is flat. But isn't there a command like, FindHeight or something?


If player_y#=0



How likely is it that y# will equal exactly zero in a floating point system? To be on the safe side I'd check to see if it is less than a small height rather than equal to zero or, better still, check for an actual collision with the floor before allowing a jump.

Collisions! Obviously!

If EntityCollided(player,ground)
  If KeyHit(57)
    player_speed_y = 1.0
  EndIf
EndIf