Problem with newton jump code?
Blitz3D Forums/Blitz3D Programming/Problem with newton jump code?
| ||
I have been researching newton a bit & i have a bit of a problem with a few functions. Can SOMEONE PLEASE help me fix this code, so my player will NEVER get stuck in the air, my player wont automatically bounce when it moves over a hilly point, and can someone help me get an animated mesh to move around with an animation, and jump with an animation? use psionics ninja model as the animated model in directx format. here's the code: Graphics3D 800, 600, 0, 2 Include "Newton.bb" AmbientLight 255,255,255 Global cam cam = CreateCamera() CameraRange cam, .1, 999999999 Global sky sky = CreateSphere(100.5) EntityColor sky, 102, 102, 255 FlipMesh sky ScaleEntity sky, 999999999,999999999,999999999 ; -- create physic world phWorldCreate(0,"your license key") phMatSetDefFriction(.9,.8) ;set the friction for player material to zero matHero = phMatCreate() phMatSetFriction(matHero,0,0,0) ; -- load level and create physic for it levelmesh = LoadMesh("level.b3d") ScaleMesh levelmesh,5,5,5 celltex = LoadTexture("cell.bmp") ScaleTexture celltex,.01,.01 EntityTexture levelmesh,celltex Global char.phx = phxCreatebox(2,5,2,10.2) ;(2,5,2,10.2) phBodySetPos(char\body,0,5,0) charvector = phJointUpVectorCreate(0,1,0,char\body) phBodySetDamping(char\body,1,1) phLevelBuildBegin() LevelAddMesh(levelmesh) phLevelBuildEnd() MoveMouse GraphicsWidth()/2,GraphicsHeight()/2 HidePointer While Not KeyHit(1) UpdateChar2() PositionEntity sky, EntityX(char\mesh), EntityY(char\mesh), EntityZ(char\mesh) UpdateWorld MoveMouse GraphicsWidth()/2,GraphicsHeight()/2 WorldStep(0.5) RenderWorld Color 0,0,0 Oval GraphicsWidth()/2-1,GraphicsHeight()/2-1,3,3 Color 255,255,255 Plot GraphicsWidth()/2,GraphicsHeight()/2 Text 10,10,"Y:"+phBodyGetY(char\body) Flip Wend Function UpdateChar() ;moving character maxforce# = 5.0 ;max force ;Is there something under legs? x# = phBodyGetX(char\body) y# = phBodyGetY(char\body) z# = phBodyGetZ(char\body) If (phRayCast(x,y,z,x,y-5.1,z)) ;Calculate force from keys TFormVector maxforce*(KeyDown(32)-KeyDown(30)),maxForce*30*KeyDown(57),maxforce*(KeyDown(17)-KeyDown(31)),0,0 fx# = TFormedX() fy# = TFormedY() fz# = TFormedZ() phBodyAddRelForce(char\body,fx,fy,fz) ;stop body if no force was applied If (fx = 0) And (fz = 0) And (fy=0) phBodySetVel(char\body,0,0,0) EndIf phBodySetDamping(char\body,1,1) Else phBodySetDamping(char\body,0,1) EndIf ;reposition camera phBodySetOmega(char\body,0,Float(MouseXSpeed())/3.0,0) PositionEntity cam,EntityX(char\mesh,1),EntityY(char\mesh,1),EntityZ(char\mesh,1),1 RotateEntity cam,EntityPitch(cam)+Float(MouseYSpeed())/3.0,EntityYaw(char\mesh),0,1 ;shot If MouseHit(1) TFormPoint 0,0,1000,cam,0 If phRayCast(EntityX(cam,1),EntityY(cam,1),EntityZ(cam,1),TFormedX(),TFormedY(),TFormedZ()) shotedbody = phRayGetBody() mass# = phBodyGetMass(shotedBody) TFormVector 0,0,10,cam,0;bullet impulse dvelx# = TFormedX()/mass; dvely# = TFormedY()/mass; dvelz# = TFormedZ()/mass phBodyAddImpulse(shotedbody,phRayGetX(),phRayGetY(),phRayGetZ(),dvelx,dvely,dvelz) PlaySound(snd) EndIf EndIf End Function Function UpdateChar2();another example of character controller ;moving char maxvel# = 15.0 ;max velocity ;Is there anything under legs? x# = phBodyGetX(char\body) y# = phBodyGetY(char\body) z# = phBodyGetZ(char\body) If (phRayCast(x,y,z,x,y-5.1,z));if there's the ground ;desired velocity TFormVector (KeyDown(32)-KeyDown(30)),0,(KeyDown(17)-KeyDown(31)),cam,0 vx# = TFormedX()*maxvel vy# = TFormedY()*maxvel vz# = TFormedZ()*maxvel ;current velocity vxcur# = phBodyGetVelX(char\body) vycur# = phBodyGetVelY(char\body) vzcur# = phBodyGetVelZ(char\body) ;change in velocity dvx# = (vx-vxcur);*.1 If (vx*vx+vz*vz)<.001 Then dvy# = vy - vycur Else dvy# = 0 dvz# = (vz-vzcur);*.1 phBodyAddImpulse(char\body,x,y,z,dvx,dvy,dvz) ;jump If KeyDown(57) phBodyAddForce(char\body,0,5000,0) Else;if in air phBodySetDamping(char\body,0,1) EndIf ;position camera phBodySetOmega(char\body,0,Float(MouseXSpeed())/3.0,0) PositionEntity cam,EntityX(char\mesh,1),EntityY(char\mesh,1),EntityZ(char\mesh,1),1 RotateEntity cam,EntityPitch(cam)+Float(MouseYSpeed())/3.0,EntityYaw(char\mesh),0,1 ;shot If MouseHit(1) TFormPoint 0,0,1000,cam,0 If phRayCast(EntityX(cam,1),EntityY(cam,1),EntityZ(cam,1),TFormedX(),TFormedY(),TFormedZ()) shotbody = phRayGetBody() mass# = phBodyGetMass(shotBody) TFormVector 0,0,10,cam,0;bullet impulse dvelx# = TFormedX()/mass; dvely# = TFormedY()/mass; dvelz# = TFormedZ()/mass phBodyAddImpulse(shotbody,phRayGetX(),phRayGetY(),phRayGetZ(),dvelx,dvely,dvelz) PlaySound(snd) EndIf EndIf End Function Function UpdateChar3();third example of character controller ;moving char maxvel# = 15.0 ;max velocity ;Is there anything under legs? x# = phBodyGetX(char\body) y# = phBodyGetY(char\body) z# = phBodyGetZ(char\body) If (phRayCast(x,y,z,x,y-5.5,z));if there's the ground ;desired velocity TFormVector (KeyDown(32)-KeyDown(30)),0,(KeyDown(17)-KeyDown(31)),cam,0 vx# = TFormedX()*maxvel vy# = TFormedY()*maxvel vz# = TFormedZ()*maxvel ;desired velocity projected on the ground plane nx# = phRayGetNX() ny# = phRayGetNY() nz# = phRayGetNZ() lambda# = (vx*nx+vy*ny+vz*nz) vprojx# = vx - lambda*nx vprojy# = vy - lambda*ny vprojz# = vz - lambda*nz ;current velocity vxcur# = phBodyGetVelX(char\body) vycur# = phBodyGetVelY(char\body) vzcur# = phBodyGetVelZ(char\body) ;change in velocity dvx# = (vprojx-vxcur);*.1 If (vx*vx+vz*vz)<.001 Then dvy# = vy - vycur Else dvy# = 0 dvz# = (vprojz-vzcur);*.1 ;dvy# = (vprojy-vycur);*.1 phBodyAddImpulse(char\body,x,y,z,dvx,dvy,dvz) ;jump If KeyDown(57) phBodyAddForce(char\body,0,5000,0) EndIf Else;if in air phBodySetDamping(char\body,0,1) EndIf ;position camera phBodySetOmega(char\body,0,Float(MouseXSpeed())/3.0,0) PositionEntity cam,EntityX(char\mesh,1),EntityY(char\mesh,1),EntityZ(char\mesh,1),1 RotateEntity cam,EntityPitch(cam)+Float(MouseYSpeed())/3.0,EntityYaw(char\mesh),0,1 ;shot If MouseHit(1) TFormPoint 0,0,1000,cam,0 If phRayCast(EntityX(cam,1),EntityY(cam,1),EntityZ(cam,1),TFormedX(),TFormedY(),TFormedZ()) shotbody = phRayGetBody() mass# = phBodyGetMass(shotBody) TFormVector 0,0,10,cam,0; dvelx# = TFormedX()/mass; dvely# = TFormedY()/mass; dvelz# = TFormedZ()/mass phBodyAddImpulse(shotbody,phRayGetX(),phRayGetY(),phRayGetZ(),dvelx,dvely,dvelz) PlaySound(snd) EndIf EndIf End Function ANY help is GREATLY appreciated! :) Thanks! :) ~DS~ |