Jump Limit

Blitz3D Forums/Blitz3D Beginners Area/Jump Limit

Ace Killjoy(Posted 2008) [#1]
I know how to jump, I know how to put velocity on a jump.
What I don't know is how to jump for only one second and not be able to jump in mid air and still have velocity in my jump.
Any advice for this problem would be greatly appreciated.


Nate the Great(Posted 2008) [#2]
Try only letting the player jump if the y velocity is zero or close to zero.


Nate the Great(Posted 2008) [#3]



I think this bouncing ball program will help you.
Press space to bounce.


Nate the Great(Posted 2008) [#4]
I will be glad to help you again if you have any problems.


IcyDefiance(Posted 2008) [#5]
I had the same problem for a game I'm working on. I figured out a really easy way to do it, and this will work with anything. You don't have to have a flat terrain or anything.

Collisions playerType,lvlType,2,3

If KeyHit(57) And CountCollisions(player) > 0
    ;Take action here
EndIf


KeyHit(57) = The Space key
playerType = Type of player that is jumping
lvlType = Whatever the ground is, or anything else that the player can jump from.
player = Entity of jumping player


Stevie G(Posted 2008) [#6]
@ Yippe .. so if you are pushed up against a wall in mid air you can still jump?

Best to check if you are on the ground so ...

If KeyHit( 57 ) and OnGround( Player )
    ;Take Action Here
Endif

;===========================================
;===========================================
;===========================================

Function OnGround( Entity )

   OnGround = false

   for c = 1 to countcollisions( Entity )
      if collisionny( Entity, c ) > 0
         OnGround = true
         exit
      endif
    next

    return OnGround

End function



IcyDefiance(Posted 2008) [#7]
@ Yippe .. so if you are pushed up against a wall in mid air you can still jump?


Not if you assign a different type to the walls than to the ground. If they're in the same mesh, that's the only thing I can think of that would ruin my code.


Ace Killjoy(Posted 2008) [#8]
Thanks for the advice everyone.
I shall test these ideas.


Ace Killjoy(Posted 2008) [#9]
Unfortunately, none of these suggestions worked.
It's probably my lousy coding skills (I'm not completely sure what ";Take Action Here" means).

This is the code I have so far:

;Jump
If KeyDown(54)=True Then velocity#=1
If Not KeyDown(54)=True Then velocity#=velocity#-.008
TranslateEntity cam,0,velocity#,0
If CountCollisions(cam)=True Then velocity#=0

;Gravity
TranslatEntity cam,0,-.35,0 


cam=Camera
I've set up collisions for cam and the terrain.
If possible, I would really like to keep the velocity settings.


IcyDefiance(Posted 2008) [#10]
I can see something...I think.

First of all, you need a Collisions statement. Otherwise, countcollisions will always be 0, because it's not sensing anything new. You also need an UpdateWorld statement, and you need to set a radius for the jumping entity. (Not sure if you can with a camera, you might need to parent it to something, but you probably can.) You may have these, but thought I'd mention it.

Second, most of the time, KeyHit() is used to jump, not key down. Otherwise, someone could just hold the key down and fly.

Third, at least if you're using my code, which you don't have to. You want to do:
If KeyHit(54)=True And CountCollisions(cam)=True Then velocity#=1


P.S. This won't fix your bug, but if you want your code a little neater, you can use a simple Else instead of "If Not KeyDown(54)=True Then"


Nate the Great(Posted 2008) [#11]
Does anyone know how a you can allow a player to doublejump but not tripple jump like in Mario?


Ace Killjoy(Posted 2008) [#12]
@ Yippee
Awesome! That change worked. The height of my jump is now controlled by the velocity.

@ Nate the Great
This is just guess, but perhaps a Select... Case statement would work.
I.E. Case 1 lets you jump,
Case 2 lets you jump again (probably repeating the first code)
Case 3 would let gravity bring you back down without jumping again.

That's just a guess but I may try it myself some time.
Not exactly sure what the actual jump code would be for that instance.


IcyDefiance(Posted 2008) [#13]
Does anyone know how a you can allow a player to doublejump but not tripple jump like in Mario?


Ace Killjoy is partly right. You would use something like this. (This will make "Mario" jump twice as far his second jump, like in the games...if I remember right.)

jumping = 0

If KeyHit(57) And jumping = 0
    velocity# = 1
    jumping = 1
ElseIf KeyHit(57) And jumping = 1
    velocity# = 2
    jumping = 2
EndIf

If EntityCollided(player,groundType)
    velocity# = 0
    jumping = 0
EndIf


You could use a select...case statement, just my style is to use if...else.


Nate the Great(Posted 2008) [#14]
It works! Thanks for the help.