legs moving on jump
Blitz3D Forums/Blitz3D Beginners Area/legs moving on jump
| ||
I've created a cute little character, and a self-sufficient program that will have him talk and jump, and rotate the camera to change the view. My problem now is that whenever he jumps, his legs move halfway up the body (run program for yourself if needed) anybody have any suggestions? |
| ||
code = ;spike ;setup Graphics3D 800,600,16,3 SetBuffer BackBuffer() SeedRnd(MilliSecs()) ;create camera camera = CreateCamera() PositionEntity camera,0,0,-5 camerapivot = CreatePivot() EntityParent camera,camerapivot ;create light light = CreateLight() type_player = 1 type_ground = 2 ;create body parts and ground spike = CreateCone(4) eyepivot = CreatePivot() eye1 = CreateSphere(8,eyepivot) eye2 = CreateSphere(8,eyepivot) pupil1 = CreateSphere(8,eyepivot) pupil2 = CreateSphere(8,eyepivot) legpivot = CreatePivot() leg1 = CreateCylinder(8,True,legpivot) leg2 = CreateCylinder(8,True,legpivot) mouthpivot = CreatePivot() mouth = CreateCube(mouthpivot) wingpivot = CreatePivot() wing1 = CreateCylinder(8,True,wingpivot) wing2 = CreateCylinder(8,True,wingpivot) ground = CreateTerrain(512) ;resize body parts ScaleEntity mouth,0.5,0.01,0.5 ScaleEntity wing1,0.75,0.05,0.25 ScaleEntity wing2,0.75,0.05,0.25 ScaleEntity leg1,0.25,0.5,0.25 ScaleEntity leg2,0.25,0.5,0.25 ScaleEntity eye1,0.2,0.2,0.2 ScaleEntity eye2,0.2,0.2,0.2 ScaleEntity pupil1,0.1,0.1,0.1 ScaleEntity pupil2,0.1,0.1,0.1 ;place body parts and ground PositionEntity mouth,0,-0.98,-0.005 PositionEntity spike,0,0,0 PositionEntity leg1,-0.5,-1.45,0 PositionEntity leg2,0.5,-1.45,0 PositionEntity eye1,-0.25,0,-0.25 PositionEntity eye2,0.25,0,-0.25 PositionEntity pupil1,-0.25,0,-0.4 PositionEntity pupil2,0.25,0,-0.4 PositionEntity wing1,-0.75,-0.25,0.35 PositionEntity wing2,0.75,-0.25,0.35 PositionEntity ground,-500,-1.95,-500 ;color and rotate body parts and ground EntityColor spike,254,240,65 EntityColor leg1,254,240,65 EntityColor leg2,254,240,65 EntityColor pupil1,0,150,0 EntityColor pupil2,0,150,0 EntityColor mouth,254,240,65 EntityColor wing1,220,220,220 EntityColor wing2,220,220,220 EntityColor ground,0,230,0 RotateEntity wing1,90,0,0 RotateEntity wing2,90,0,0 ;parent all body parts together EntityParent eyepivot,spike EntityParent legpivot,spike EntityParent mouthpivot,spike EntityParent wingpivot,spike ;setup collisions EntityType spike,type_player,True EntityType ground,type_ground Collisions type_player,type_ground,2,3 EntityRadius spike,1 ;declare variables needed for loop pitch# = 0 yaw# = 0 speak = 0 speakr = 0 speed# = 0.00 jump = 0 While Not KeyDown(1) ;this loop makes character jump if space bar is pressed, open and close mouth ;if shift key is pressed, and rotate camera on a pivot if the arrow keys are pressed If KeyDown(54) And speak = 0 Then speak = 1 If KeyHit(57) Then jump = 1:speed# = 1 If KeyDown(203) Then yaw# = yaw# - 1 If KeyDown(205) Then yaw# = yaw# + 1 If KeyDown(208) Then pitch# = pitch# - 1 If KeyDown(200) Then pitch# = pitch# + 1 If speak = 1 Then speakr = speakr - 1 If speak = 2 Then speakr = speakr + 1 If speakr <=-45 Then speak = 2 If speakr >= 0 And speak > 0 Then speak = 0 RotateEntity camerapivot,pitch#,yaw#,0 RotateEntity mouth,speakr,0,0 MoveEntity spike,0,speed#,0 If jump = 1 Then speed# = speed# - 0.05 If speed# < 0 And CountCollisions(spike) > 0 jump = 0 speed# = 0 EndIf UpdateWorld() RenderWorld() Flip Wend |
| ||
Gday. I have just changed a few things around. There maybe other ways to do it but i usualy set up globals at the start for collisions as well as the collisions. I am a bit of a noob myself at this so i am sure there are many ways to do it but.. Here you goGraphics3D 800,600,16,3 SetBuffer BackBuffer() SeedRnd(MilliSecs()) ; create collisions as globals at the start Global type_player = 1 Global type_ground = 2 Collisions type_player,type_ground,2,3 ;create camera camera = CreateCamera() PositionEntity camera,0,0,-5 camerapivot = CreatePivot() EntityParent camera,camerapivot ;create light light = CreateLight() ;create spike & setup collisions spike = CreateCone(4) EntityRadius spike,1.95 EntityType spike,type_player,True ;create body parts and ground eyepivot = CreatePivot(spike) ; you can parent your piviots to other entitys as you go instead of using entityparent eye1 = CreateSphere(8,eyepivot) eye2 = CreateSphere(8,eyepivot) pupil1 = CreateSphere(8,eyepivot) pupil2 = CreateSphere(8,eyepivot) legpivot = CreatePivot(spike) leg1 = CreateCylinder(8,True,legpivot) leg2 = CreateCylinder(8,True,legpivot) mouthpivot = CreatePivot(spike) mouth = CreateCube(mouthpivot) wingpivot = CreatePivot(spike) wing1 = CreateCylinder(8,True,wingpivot) wing2 = CreateCylinder(8,True,wingpivot) ground = CreateTerrain(512) EntityType ground,type_ground ;resize body parts ScaleEntity mouth,0.5,0.01,0.5 ScaleEntity wing1,0.75,0.05,0.25 ScaleEntity wing2,0.75,0.05,0.25 ScaleEntity leg1,0.25,0.5,0.25 ScaleEntity leg2,0.25,0.5,0.25 ScaleEntity eye1,0.2,0.2,0.2 ScaleEntity eye2,0.2,0.2,0.2 ScaleEntity pupil1,0.1,0.1,0.1 ScaleEntity pupil2,0.1,0.1,0.1 ;place body parts and ground PositionEntity mouth,0,-0.98,-0.005 PositionEntity spike,0,0,0 PositionEntity leg1,-0.5,-1.45,0 PositionEntity leg2,0.5,-1.45,0 PositionEntity eye1,-0.25,0,-0.25 PositionEntity eye2,0.25,0,-0.25 PositionEntity pupil1,-0.25,0,-0.4 PositionEntity pupil2,0.25,0,-0.4 PositionEntity wing1,-0.75,-0.25,0.35 PositionEntity wing2,0.75,-0.25,0.35 PositionEntity ground,-500,-1.95,-500 ;color and rotate body parts and ground EntityColor spike,254,240,65 EntityColor leg1,254,240,65 EntityColor leg2,254,240,65 EntityColor pupil1,0,150,0 EntityColor pupil2,0,150,0 EntityColor mouth,254,240,65 EntityColor wing1,220,220,220 EntityColor wing2,220,220,220 EntityColor ground,0,230,0 RotateEntity wing1,90,0,0 RotateEntity wing2,90,0,0 ;declare variables needed for loop pitch# = 0 yaw# = 0 speak = 0 speakr = 0 speed# = 0.00 jump = 0 While Not KeyDown(1) ;this loop makes character jump if space bar is pressed, open and close mouth ;if shift key is pressed, and rotate camera on a pivot if the arrow keys are pressed If KeyDown(54) And speak = 0 Then speak = 1 If KeyHit(57) Then jump = 1:speed# = 1 If KeyDown(203) Then yaw# = yaw# - 1 If KeyDown(205) Then yaw# = yaw# + 1 If KeyDown(208) Then pitch# = pitch# - 1 If KeyDown(200) Then pitch# = pitch# + 1 If speak = 1 Then speakr = speakr - 1 If speak = 2 Then speakr = speakr + 1 If speakr <=-45 Then speak = 2 If speakr >= 0 And speak > 0 Then speak = 0 RotateEntity camerapivot,pitch#,yaw#,0 RotateEntity mouth,speakr,0,0 MoveEntity spike,0,speed#,0 If jump = 1 Then speed# = speed# - 0.05 If speed# < 0 And CountCollisions(spike) > 0 jump = 0 speed# = 0 EndIf UpdateWorld() RenderWorld() Flip Wend |