Page 1 of 1

EntityPhysicBody on mesh is off

Posted: Sat Nov 09, 2013 10:02 pm
by box_80
Hi, the EntityPhysicBody on my mesh is off. Only #PB_Entity_ConvexHullBody seem to work corretly. Can someone please tell me how to fix it. Push F5 to see where the mesh and PhysicBody is wrong on the red ninja.

Code: Select all


#CameraSpeed = 1

IncludeFile "Screen3DRequester.pb"

Define.f KeyX, KeyY, MouseX, MouseY, RollZ

If InitEngine3D()
  
  Add3DArchive("Data/Textures", #PB_3DArchive_FileSystem)
  Add3DArchive("Data/Models", #PB_3DArchive_FileSystem)
  Add3DArchive("Data/Packs/desert.zip", #PB_3DArchive_Zip)
    
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  If Screen3DRequester()
    
    NinjaMesh = LoadMesh(#PB_Any, "Ninja.mesh")
    
    LandScapeMesh = CreatePlane(#PB_Any, 100, 100, 30, 30, 30, 30)
   
    NinjaGrTex = LoadTexture(#PB_Any, "nskingr.jpg")
    NinjaRdTex = LoadTexture(#PB_Any, "nskinrd.jpg")
    LandScapeTex = LoadTexture(#PB_Any, "Dirt.jpg")
        
    NinjaGrMat = CreateMaterial(#PB_Any, TextureID(NinjaGrTex))
    NinjaRdMat = CreateMaterial(#PB_Any, TextureID(NinjaRdTex))
    LandScapeMat = CreateMaterial(#PB_Any, TextureID(LandScapeTex))
      
    NinjaGreen = CreateEntity(#PB_Any, MeshID(NinjaMesh), MaterialID(NinjaGrMat),-80,80,-1050)
    NinjaRed = CreateEntity(#PB_Any, MeshID(NinjaMesh), MaterialID(NinjaRdMat),80,80,-1050)
    LandScape = CreateEntity(#PB_Any, MeshID(LandScapeMesh), MaterialID(LandScapeMat), 0, -100, -1000)
        
    EnableWorldPhysics(#True)
    
    ScaleEntity(LandScape, 15, 15, 15)
        
    SkyBox("desert07.jpg")
        
    EntityPhysicBody(NinjaGreen, #PB_Entity_ConvexHullBody)
    EntityPhysicBody(NinjaRed, #PB_Entity_BoxBody)
    EntityPhysicBody(LandScape, #PB_Entity_StaticBody) 
    
    EntityAngularFactor(NinjaGreen, 0, 1, 0)
    EntityAngularFactor(NinjaRed, 0, 1, 0)
    
    WorldGravity(-50)
    CreateCamera(0, 0, 0, 100, 100)
    
    MoveCamera(0, 0, 10, 200, #PB_Relative)
           
    Repeat
      Screen3DEvents()
      
      If ExamineMouse()
        MouseX = -MouseDeltaX() * #CameraSpeed * 0.05
        MouseY = -MouseDeltaY() * #CameraSpeed * 0.05
        
        RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
                          
      EndIf
      
      If ExamineKeyboard()
        
        If KeyboardReleased(#PB_Key_F5)
          WorldDebug(#PB_World_DebugBody)
        ElseIf KeyboardReleased(#PB_Key_F6)
          WorldDebug(#PB_World_DebugEntity)
        ElseIf KeyboardReleased(#PB_Key_F7)
          WorldDebug(#PB_World_DebugNone)
        EndIf
                
        If KeyboardPushed(#PB_Key_Left)
          KeyX = -#CameraSpeed
        ElseIf KeyboardPushed(#PB_Key_Right)
          KeyX = #CameraSpeed
        Else
          KeyX = 0
        EndIf
        
        If KeyboardPushed(#PB_Key_Up)
          KeyY = -#CameraSpeed
        ElseIf KeyboardPushed(#PB_Key_Down)
          KeyY = #CameraSpeed
        Else
          KeyY = 0
        EndIf    
        
      EndIf
      
      RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
      MoveCamera  (0, KeyX, 0, KeyY)
      
      RenderWorld()
      Screen3DStats()
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  EndIf
  
Else
  MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf

End


Re: EntityPhysicBody on mesh is off

Posted: Sun Nov 10, 2013 7:18 am
by applePi
Hi

insert WorldDebug(#PB_World_DebugBody) in line 52 before Repeat, and you will see that the red ninga in box while the gree ninja are in exact shape.
Image
so evey mesh have its suitable convex physics body. replace red ninja with a box and it will land exactly, replace the red ninja with a sphere and it will not roll on the ground because it has a box body while it should be #PB_Entity_SphereBody for the sphere

Re: EntityPhysicBody on mesh is off

Posted: Sun Nov 10, 2013 1:41 pm
by box_80
The title and topic description may cause misunderstanding. Sorry about that. What I mean is the physics body don't surround the red ninja mesh correctly so the ninja feet will rest on the plane below it instead of floating above it. In the ThirdPerson.pb in the Purebasics demo example. EntityPhysicBody with a CapsuleBody work correctly, but in my example it don't. That is what I'm trying to find out. I'm not sure I understand what your saying. Could you give me a example of your own or change my example so it works. So I can learn from, or a link that would help.

Image

Image

Edit: After looking at the ThirdPerson.pb more in detail. I starting to see I may have missed something with that HideEntity part. Thanks for the help.