1
\$\begingroup\$

I am making a game in Blitz3d and I made simple gravity, however once the object falls on the ground, it goes through it very slowly. The ground is a plane and I have collision on it.

This is a pretty old engine, and not a lot of people are using it but I decided to use it because it's easier than Unity3D for me and it's very basic and customizable.

Here's my code:

AppTitle "FPS" Graphics3D 800,600,32,2 SetBuffer BackBuffer() SeedRnd MilliSecs() HidePointer ;Objects Global player = CreatePivot() Global camera = CreateCamera(player) Global cube = CreateCube() Global light = CreateLight() Global plane = CreatePlane() Global cube2 = CreateCube(player) col_plane = 1 col_player = 2 col_cube = 3 ;Vars gravity# = -.00001 plx# = 0 ply# = 0 plz# = 0 pldx# = 0 pldy# = 0 pldz# = 0 ;Textures CameraClsColor camera,135,206,250 box = LoadTexture("models\box.png") dirt = LoadTexture("models\dirt.jpg") ;Object Details EntityType cube,col_cube EntityType player,col_player EntityType plane,col_plane EntityRadius player,1.2 EntityRadius plane,1 PositionEntity player,0,10,5 PositionEntity cube,0,1,5 PositionEntity light,0,2,0 PositionEntity plane,0,0,0 EntityTexture cube,box EntityTexture plane,dirt ScaleTexture dirt,5,5 CameraRange camera,0.25,200 ;Called Functions While Not KeyHit(1) Cls ;Collisions Collisions col_player,col_plane,2,2 Collisions col_player,col_cube,2,2 If ply < -2 Then ply = 0 pldy = -pldy*.39 EndIf If ply < -1.8 Then pldx = .6*pldx pldz = .6*pldz If KeyDown(57) Then pldy = 2 EndIf pldy = pldy + gravity plx = plx + pldx ply = ply + pldy plz = plz + pldz PositionEntity player,EntityX(player)+plx,EntityY(player)+ply,EntityZ(player)+plz control() RenderWorld() UpdateWorld() MoveMouse GraphicsWidth()/2, GraphicsHeight()/2 Flip Wend End ;Functions Function control() If KeyDown(42) ;Shift (for running) If KeyDown(17) And KeyDown(30) ;W and A MoveEntity player,-0.15,0,0.15 ElseIf KeyDown(17) And KeyDown(32) ;W and D MoveEntity player,0.15,0,0.15 ElseIf KeyDown(17) And KeyDown(30) ;S and A MoveEntity player,-0.15,0,-0.15 ElseIf KeyDown(17) And KeyDown(32) ;S and D MoveEntity player,0.15,0,-0.15 ElseIf KeyDown(17) ;W MoveEntity player,0,0,0.15 ElseIf KeyDown(31) ;S MoveEntity player,0,0,-0.15 ElseIf KeyDown(30) ;A MoveEntity player,-0.15,0,0 ElseIf KeyDown(32) ;D MoveEntity player,0.15,0,0 End If Else ;Walking If KeyDown(17) And KeyDown(30) ;W and A MoveEntity player,-0.1,0,0.1 ElseIf KeyDown(17) And KeyDown(32) ;W and D MoveEntity player,0.1,0,0.1 ElseIf KeyDown(17) And KeyDown(30) ;S and A MoveEntity player,-0.1,0,-0.1 ElseIf KeyDown(17) And KeyDown(32) ;S and D MoveEntity player,0.1,0,-0.1 ElseIf KeyDown(17) ;W MoveEntity player,0,0,0.1 ElseIf KeyDown(31) ;S MoveEntity player,0,0,-0.1 ElseIf KeyDown(30) ;A MoveEntity player,-0.1,0,0 ElseIf KeyDown(32) ;D MoveEntity player,0.1,0,0 End If End If While KeyDown(16) ;Q RotateEntity camera,MouseXSpeed(),10,10 Wend While KeyDown(18) ;E RotateEntity camera,0,-10,-10 Wend TurnEntity player, 0, -MouseXSpeed()/6.0, 0 TurnEntity camera, MouseYSpeed()/6.0, 0, 0 If EntityPitch(camera) < -70 RotateEntity camera, -70, EntityYaw(camera), EntityRoll(camera) ElseIf EntityPitch(camera) > 70 RotateEntity camera, 70, EntityYaw(camera), EntityRoll(camera) EndIf End Function 

If there's some one who can actually help me with this, I would appreciate it.

\$\endgroup\$
3
  • \$\begingroup\$ @jhocking I just started using Blitz3D. I thought that I fell through the plane BECAUSE I didn't have a collision with it, so I am gonna fix it right now. I am also going to fix the collisions and tell you if it worked or not. \$\endgroup\$ Commented Oct 9, 2014 at 4:14
  • \$\begingroup\$ It's not really clear what about jhocking's comment worked for you. Can you post your own answer with details about how you got this to work, and what the problem was? \$\endgroup\$ Commented Oct 9, 2014 at 20:46
  • \$\begingroup\$ @Byte56 I did sir. \$\endgroup\$ Commented Oct 9, 2014 at 22:03

3 Answers 3

2
\$\begingroup\$

(Blitz3D, blast from the past!)

It's been so long so a bunch of things I'm wondering about (these may or may not be relevant to your question): Why are you setting a collision radius for the plane? Why are you calling 'Collisions' every frame, rather than once when declaring the collision types? Shouldn't UpdateWorld() be before RenderWorld()?

All three of these things are related to collision detection, and are oddities I spotted in your code:

1) The plane shouldn't have a collision radius defined, since it will be used for polygon collisions and not sphere collisions.

2) The 'Collisions' command sets the relationship between various collision types, so it only needs to be set once to say "this type of object collides with that type of object"

3) Collision detection is actually applied during UpdateWorld(), so you would want the simulation to resolve collisions before drawing the frame.

\$\endgroup\$
2
  • \$\begingroup\$ This might be the hint that lead to a solution, but I don't think it's an answer on its own. \$\endgroup\$ Commented Oct 9, 2014 at 18:28
  • \$\begingroup\$ yeah this was a comment at first, but he asked for it as an answer after I helped him. and I was wondering which part actually solved the problem, but it looks like he did all three things \$\endgroup\$ Commented Oct 10, 2014 at 0:21
1
\$\begingroup\$

I am posting my own answer saying exactly what I did.

First off, I moved

Collisions col_player,col_cube,2,2 Collisions col_player,col_plane,2,2 

out of the While Not KeyHit(1) loop, as that might have conflicted with my current gravity code. Second off, I removed EntityRadius plane,1, and thirdly I put UpdateWorld() before RenderWorld(), and everything works just as expected now! Big thanks to @jhocking!

\$\endgroup\$
0
\$\begingroup\$

so this is pretty easy... collision detection is the best method- once you have the collisions between terrain or plane and your player entity then do this...

your code:

ElseIf KeyDown(30) ; MoveEntity player,-0.1,0,0 

change to:

ElseIf KeyDown(30) ; MoveEntity player,-0.1,-0.1,0 

This way there will be a downward Y force on the player- this will make it more difficult to climb rising terrain and also provide for a falling motion.

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.