How to determine if the character can jump or not

Blitz3D Forums/Blitz3D Beginners Area/How to determine if the character can jump or not

UnderwoodNullium(Posted 2008) [#1]
How can I determine whether to let the character jump or not when I press the jump key? The character should only be able to jump if he is on the ground. I'm VERY new to the Blitz3D commands but my guess is I would do a 'linepick' with a radius equal to that of my character from the bottom of my character to a small amount straight down, and if the linepick "picks" (??) my level mesh then allow the character to jump? That's the basic idea, right? So... is this partly right?

bbLinePick(bbEntityX(character),bbEntityY(character)+character_radius,bbEntityZ(character),0,0.1,0)


Do a line pick from the bottom of my character to just a LITTLE bit lower and see if it overlaps the level mesh? Can someone show me exactly how to do this? I don't know if this is the right approach. If not, then can someone show me the best way to do what I want to do?

Thank you so much.

EDIT: I found the solution in a thread called 'Jump Limit'. But I'm still wondering exactly how to use linepick properly, so if someone could show me it would be much appreciated.


Ross C(Posted 2008) [#2]
Well, the linepick from the characters location is all you need to do. Simply do this downward, half the height of your character. It all depends where the centre of your character lies. Some people have the character with the local axis centred on the characters feet.

So, do a linepick downwards and then: (Btw, you need to do a minus number on the Y axis, if your picking downwards.

If PickedEntity() <> 0 then
     ; Put code for jumping in here
End if


Your checking if any entity was picked by the linepick. If it was, then start the jump. Your best to set a variable:

jumping = 1


and constantly check with the same linepick if he has touched the floor:


linepick blah blah

If PickedEntity() <> 0 = then
   If jumping = 1 then
      ; character has just landed
      ; set jumping = 0
   ElseIf jumping = 0 then
      ; character can jump
      ; set jumping = 1
      ; move character upwards for jump
   End if
Else ; nothing picked
   If jumping = 1 then
      ; character is still in mid air. No change.
   ElseIf jumping = 0 then
      ; there's a good chance your character has just walked off a ledge.
      ; set jumping = 1
      ; set the character to move downwards (fall)
End if



That should do what you need :o)


UnderwoodNullium(Posted 2008) [#3]
Awesome, thanks! How do I test to see if the picked entity was a certain entity? In other words, if I wanted to test to see if the picked entity was 'level', then how would I do that?


UnderwoodNullium(Posted 2008) [#4]
And one more thing, I used the following code for a walljump, but it's not working:
If bbKeyHit(bbkey_x)
bbLinePick(bbEntityX(character),bbEntityY(character),bbEntityZ(character),0,0,1.2)
  If onground(character) = 1 Then charyspd = 0.5
    If bbPickedEntity()<>0
      charyspd = 0.5
    End If
End If


Basically, I wanna test if there's a wall in front of it, and if so, allow it to walljump. The first test is for normal jumping, and the picked entity part of it is for the walljump. Why is it not working?


Ross C(Posted 2008) [#5]
sphere = createsphere()

If PickedEntity() = sphere then
   ; smae entity
End if


Well, as for the wall jump, i'd only test for a wall jump, if the character is in the air, and has a forward speed.

You best to use the collision system for this i reckon.

If EntityCollided() = wall then
   If jumping = 1
      ;enable wall jump
   End if
End if


I reckon that would be a simplier way to do this. I've never tried a wall jump like that in code though, but i reckon that's the way it should work.


UnderwoodNullium(Posted 2008) [#6]
Oh! Thanks, haha, that's pretty simple for the picked entity thing. And for the wall jump, if I had a wall entity then it would be easier, but I only have a level mesh. I don't know why what I tried didn't work.


Ross C(Posted 2008) [#7]
If you have a wall mesh, then you'll need to check the normals of the collision then. The collision normals (CollisionNX() etc etc) return basically an angle at which the collision occured. Using this, you could determine whether the geometry encountered is steep enough to be considered a wall.

If bbKeyHit(bbkey_x)
bbLinePick(bbEntityX(character),bbEntityY(character),bbEntityZ(character),0,0,1.2)
  If onground(character) = 1 Then charyspd = 0.5
    If bbPickedEntity()<>0
      charyspd = 0.5
    End If
End If


I reckon it didn't work, because your character is still on the ground. You can't wall jump whilst standing on the ground, and when you do jump, the onground() would surely equal 0, invalidating the if statement.