I have been creating a simple 3d platform game and I needed the character to be able to jump from platform to platform. I created a little program, which you can see here, to try and create a character that can jump.
sync on
sync rate 60
gravity# = 1
jump# = 1
make object sphere 1, 5
make object plain 2, 50, 50
point object 2, 0, -50, 0
position object 2, 0, -3.5, 0
do
Y# = object angle y (1)
y# = object position y (1)
x# = object position x (1)
z# = object position z (1)
if upkey()= 1 then move object 1, 1
if downkey()= 1 then move object 1, -1
if rightkey()= 1 then yrotate object 1, Y#+5
if leftkey()= 1 then yrotate object 1, Y#-5
if spacekey()= 1
if jump# = 1
if object collision (1,2)
move object up 1, 5
jump# = 0
endif
endif
endif
if gravity# = 1
if not object collision (1,2)
move object down 1, 2
jump# = 1
endif
endif
sync
loop
There seems to be something wrong with the jumping part. If you hold the spacebar, you keep on going up. I know why this is, but I can't figure out a way to stop it. Is there something simple I am doing wrong? Or do I need to add more to my code?