Crouching Help
Blitz3D Forums/Blitz3D Beginners Area/Crouching Help
| ||
Hey everyone. I'm working on a FPS, but I've run into a problem. I want my character to crouch, and I almost have it (I think). However, the camera is shaking. Here's my what I got:;CROUCH TEST Graphics3D 800,600,32,2 SetBuffer BackBuffer() ;LOADING THE LEVEL Global type_player1=1 Global type_map=3 Global p1level#=5 Global p1grav#=0.4 Global playerbox1=CreateCube() EntityType playerbox1,type_player1 Global camera1=CreateCamera() CameraClsColor camera1,0,145,245 EntityParent camera1,playerbox1 Global ground=CreatePlane() Global groundtex=LoadTexture("grass.bmp") PositionEntity ground,0,-10,0 EntityTexture ground,groundtex ScaleTexture groundtex,15,15 EntityType ground,type_map EntityPickMode ground,2 ;COLLISIONS Collisions type_player1,type_map,2,2 ;MAIN LOOP While Not KeyDown(1) LinePick EntityX(playerbox1),EntityY(playerbox1),EntityZ(playerbox1),0,-p1level,0 If PickedEntity()=ground MoveEntity playerbox1,0,0.2,0 If PickedEntity()=0 MoveEntity playerbox1,0,-.2,0 ;CROUCH If KeyDown(30) p1level=2 Else p1level=5 UpdateWorld() RenderWorld() Flip Wend End Add any texture for the ground (you can't see the problem without a texture), and my problem is obvious. Please help? |
| ||
I think your problem is your picked entity queries. Your not leaving a dead zone for your player to stop. Imagine this: Linepick downwards. PickedEntity() = 0, so move the player down 0.2 next loop Linepick downwards. PickedEntity() = Ground, so move player up 0.2 next loop Linepick downwards. PickedEntity() = 0, so move the player down 0.2 etc etc This will continue forever. You need some logic in there to control, because right now it's just moving the playerbox up and down each frame. |
| ||
Oops. I see now. Thanks! |
| ||
I would also suggest not to use Linepick if it's not really required, because Linepick is rather slow. Here you have already parented the camera to the playersbox. Not ure if the camera has to see the box, but a crouching box wouldn't make much sense anyway, esp. in FPS view. Instead try something like this:If KeyDown(30) p1level=2 Else p1level=5 if eyeheight# < p1level then eyeheight#=eyeheight#+ 0.2 if eyeheight# > p1level then eyeheight# = p1level endif if eyeheight# > p1level then eyeheight#=eyeheight#- 0.2 if eyeheight# < p1level then eyeheight# = p1level endif positionentity camera,0,eyeheight#,0,0 Or to smooth the motion you may use something like this: if eyeheight# < p1level then eyeheight#=eyeheight#- (eyeheight# - p1level)*0.1 if eyeheight# > p1level then eyeheight# = p1level endif Last edited 2010 Last edited 2010 |