how to make a "jump" in 3D ?
Blitz3D Forums/Blitz3D Beginners Area/how to make a "jump" in 3D ?
| ||
I using a B3D file as map for my FPS game. I saw a few codes out there for FPS-jump, but most of them have a big problem : if you are in the air and press the jump button, it does not check if the player can jump, it just jumps ! So if you press the jump button lots of time, you just fly away... hehe How can i avoid that problem ? Thanks. MD |
| ||
check the height of the player when he presses the jump button? The same as you would in a 2D game. Or simply check if he's touching the floor. |
| ||
To check if the character is touching the floor use linepicks or depend on collision detection. For example, you could have gravity pulling the player down to collide with the ground and then use CollisionNY to determine if the player is touching the ground. |
| ||
This is one way to jump in 3D. (Fast editing of one of the examples that comes with BB3D) ; Jump and collision ; Einar Wedoe ; Based on the example by Paul Gerfen Graphics3D 800,600,16,2 Const CUBE_COL=1 Const SPHERE_COL=2 Global vel#=0 SetBuffer BackBuffer() camera=CreateCamera() CameraViewport camera,0,0,800,600 PositionEntity camera,0,0,-5 light=CreateLight() cube=CreateCube() PositionEntity cube,0,-5,5 EntityColor cube,70,80,190 EntityType cube,CUBE_COL sphere=CreateSphere(12) PositionEntity sphere,0,3,5 EntityColor sphere,170,80,90 EntityType sphere,SPHERE_COL Collisions SPHERE_COL,CUBE_COL,3,1 While Not KeyHit(1) vel=vel-0.01 MoveEntity sphere,0,vel,0 UpdateWorld RenderWorld If EntityCollided(sphere,CUBE_COL) Then vel=.4 If KeyDown(203) Then TurnEntity camera,0,0,2 If KeyDown(205) Then TurnEntity camera,0,0,-2 TurnEntity cube,0,1,0 TurnEntity sphere,0,-2,0 Flip Wend End |
| ||
your code works cuz its a "small world".. in a in-door FPS game, the player could be colliding with the wall (and not with the floor).. CollisionNY.. how can i use this command ? The command reference doesnt help much.. Thanx, MD |
| ||
The "normal" of a polygon is a vector pointing straight out from it perpendicularly. Thus polygons of the ground have normals pointing up. To determine the normal (or rather, just the Y component) of the polygon collided against you use CollisionNY. From the Y component you can determine if the vector is pointing up (straight up is 1, decreasing to zero as the polygon faces away.) |
| ||
ill give it a try later |