Jumping
I love making stuff with jumping!
I used to have the same problem, now I'm an expert on jumping.
The trick is to add some more variables.
Here is a perfect example on how to make things jump.
sync on
sync rate 25
autocam off
make matrix 1,2000,2000,20,20
make object sphere 1,5
make object collision Box 1,-2.5,-2.5,-2.5,2.5,2.5,2.5,0
position object 1,500,5,200
z2#=10
do
z2#=z2#+mousemovez()/100
if z2#<0 then z2#=0
if z2#>25 then z2#=25
print z2#
print screen fps()
If Leftkey()=1 then Yrotate object 1,Wrapvalue(AngleY#-2.5)
If Rightkey()=1 then Yrotate object 1,Wrapvalue(AngleY#+2.5)
If Upkey()=1
XTest# = Newxvalue(X#,AngleY#,20)
ZTest# = Newzvalue(Z#,AngleY#,20)
If XTest#>0 and XTest#<10000 and ZTest#>0 and ZTest#<10000
Move object 1,2
Endif
endif
CameraZ# = Newzvalue(Z#,AngleY#-180,20)
CameraX# = Newxvalue(X#,AngleY#-180,20)
CameraY# = 0
Position camera CameraX#,CameraY#+0+z2#,CameraZ#
Point camera X#,Y#,Z#
If Object collision(1,0)>0 then position object 1,X#,Y#,Z#
X# = Object position x(1)
Z# = Object position z(1)
Y# = Object position y(1)
AngleY# = object angle Y(1)
Rem Jumps when the user press the space key
if Jump = 0 and spacekey() = 1 `The jump variable stops the player from being kirby
`Gravity turns negative, making the player jump
Gravity# = -2.0 `This number can be changed, to make the player jump higher or lower.
Jump = 1
endif
Rem adjusting the gravity
if Jump = 1 `If the player is in the air
Inc Gravity#,.1 `increases the strength of the gravity, allowing a smooth curve when the player falls
Move object down 1,Gravity# `This makes the player fall based on the Gravity# variable
`sometimes I put a maximum speed on the gravity for collision purposes.
endif
Rem Stop the sphere from falling through the floor
Rem You might want to change this if you want more complicated collision
if Y# < 2.5
Jump = 0 `Allows the player to jump again
position object 1,X#,2.5,Z# `repositions the sphere, so it doesn't stick in the floor
endif
sync
loop
I like games, and stuff.