collisions problem

Just starting out? Need help? Post your questions and find answers here.
Henrik
Enthusiast
Enthusiast
Posts: 404
Joined: Sat Apr 26, 2003 5:08 pm
Location: Denmark

collisions problem

Post by Henrik »

Hi there
How would you go about this problem without inventing your own physics system. I have tried to illustrate the problem in the code below. It's maybe not the best way to show the problem, but i hope you understand. :(

Is there anything that i have missed or does the code actual work as it should and i just can't do it in this way? or what ? :?

The problem is not the first time the sphere is goes through the board as the board is nearly vertical, i can live with that, it is the second time where the board is close to a horizontal position.

It does'nt help to increase the radius of the sphere, because if you increase the speed a little you would have the same problem
If anybody have an idea to a solution to this problem :?: I will not kiss you but i would be very thankful :)

Thanks in advance.
and sorry for my english.
Henrik.

Code: Select all


If InitEngine3D()
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  
  OpenWindow(0,0,0,1024,768,"Ups",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
  
  OpenWindowedScreen(WindowID(0),0,0,1024,768,0,0,0)
  
  WorldShadows(#PB_Shadow_Additive)
  
  EnableWorldPhysics(1) 
   
  CreatePlane(0, 10000, 10000, 100, 100, 150, 150)
  CreateEntity(1,MeshID(0),#PB_Material_None, 0, -500, 0)
  EntityRenderMode(1, 0) 
  EntityPhysicBody(1, #PB_Entity_StaticBody)
   
 
  CreateCube(1, 1.0)
  Board=CreateEntity(#PB_Any, MeshID(1), #PB_Material_None)
  ScaleEntity(Board, 200, 2, 200) 
  EntityLocate(Board, 0, 0, 0)
  EntityPhysicBody(Board,  #PB_Entity_BoxBody ,0,0,0)
  ;EntityPhysicBody(Board, #PB_Entity_StaticBody ,0,2,1)
  
  ;CreateSphere(0, 3, 100, 100)
  CreateSphere(0, 2, 100, 100)
  Ball= CreateEntity(#PB_Any, MeshID(0), #PB_Material_None)
  ;EntityLocate(Ball, 0, 150, 0)
  EntityLocate(Ball, 0, 100, 0)
  EntityPhysicBody(Ball, #PB_Entity_SphereBody, 0.2,1,0)
  
  
  
  CreateCamera(0, 0, 0, 100, 100)
  CameraLocate(0, 220, 50, 0)
  CameraLookAt(0, EntityX(Ball) - 50, EntityY(Ball)-90,  EntityZ(Ball))
  
  CreateLight(0, RGB(255, 255, 255), 100, 800, -500)
  AmbientColor(RGB(20, 20, 20))
  
  ex.f =0  
  count = 0.5 
  
  Repeat
    
    Delay(1)
    While WindowEvent() : Wend
    
    ExamineKeyboard()       
    
    ;If EntityY(Ball) <120
    If EntityY(Ball) < 80      
      ex = ex + count            
    EndIf
    
    RotateEntity(Board,ex,0, 0)
    
    RenderWorld()
    FlipBuffers()
    
    If EntityY(Ball) < -80
      
      ex=0
      RotateEntity(Board,ex,0, 0 ) 
      FreeEntity(Ball)
      
      ;CreateSphere(0, 3, 100, 100)
      CreateSphere(0, 2, 100, 100)
      Ball= CreateEntity(#PB_Any, MeshID(0), #PB_Material_None)
      ;EntityLocate(Ball, 0, 150, 0)
      EntityLocate(Ball, 0, 100, 0)
      EntityPhysicBody(Ball, #PB_Entity_SphereBody, 0.5,1,0)
      
    EndIf
       
    
  Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  
Else
  MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf

End
Last edited by Henrik on Sun Jan 08, 2012 1:05 pm, edited 1 time in total.
gnasen
Enthusiast
Enthusiast
Posts: 282
Joined: Wed Sep 24, 2008 12:21 am

Re: collisions problem

Post by gnasen »

I dont know much about the physic engine and implementation of PB. However I think I could know the problem from other engines. If you rotate the big cube, the speed (implicit from rotation) of the cube at the collision point is very high. Its like youre throwing a ball against a wall, but the wall moves toward you. In real world there is no problem, because everything is continous, but in an engine are the states discrete. So at one point your ball is in front of the wall and in the next frame the ball and wall moved and maybe "crossed" there position.
Normally a physic engine allows a small amount of overlapping between objects, but if (like in your example) the sphere is totally sunken in the cube, the engine doesnt know what to do.
You can adjust the timestep (dont know if there is a parameter in PB) of the engine (more checks -> less mess)
Last edited by gnasen on Sat Jan 07, 2012 10:18 pm, edited 1 time in total.
pb 5.11
Henrik
Enthusiast
Enthusiast
Posts: 404
Joined: Sat Apr 26, 2003 5:08 pm
Location: Denmark

Re: collisions problem

Post by Henrik »

Hi gnasen thanks for your answer :D
gnasen wrote: There are different things you can do: First (dont know if there is a parameter in PB) you can adjust the timestep of the engine (more checks -> less mess)
if i use RenderWorld(100) the sphere seems to bounce of, i will try it out with different settings
Thanks gnasen :D

But games like table tennis would be a problem if it ball through the bat lool :lol:

Henrik
User avatar
BasicallyPure
Enthusiast
Enthusiast
Posts: 539
Joined: Thu Mar 24, 2011 12:40 am
Location: Iowa, USA

Re: collisions problem

Post by BasicallyPure »

try this before your repeat / until loop.

Code: Select all

 SetFrameRate(30)
edit:
using both SetFrameRate(30) and RenderWorld(60) seems to give good results.

B.P.
BasicallyPure
Until you know everything you know nothing, all you have is what you believe.
Henrik
Enthusiast
Enthusiast
Posts: 404
Joined: Sat Apr 26, 2003 5:08 pm
Location: Denmark

Re: collisions problem

Post by Henrik »

Hi BP
BasicallyPure wrote:try this before your repeat / until loop.

Code: Select all

 SetFrameRate(30)
edit:
using both SetFrameRate(30) and RenderWorld(60) seems to give good results.

B.P.
Yes it does :)
Thank you 8)

Btw. sorry for posting in the wrong forum, shoud have been in Game Programming :?

Best Henrik.
Post Reply