I was fiddling with PB's physic system a little bit and came across a problem.
Does anyone know if it's possible to attach an entity to another entities' skeleton and then have that first entities' physics update accordingly.
In the example I put together below. I created a Sinbad entity and then attached a cube to his right calf bone. I'd like to have the physics to be able to work on this cube as Sinbad moves around.
Sadly, It doesn't seem to work. When I use WorldDebug(#PB_World_DebugBody) I can see that the cubes' physics do exist but they just don't follow Sinbad around.
Does anyone know how to make this work if at all?
I'm using PB 5.50.
Code: Select all
;Use Up and Down arrow keys to move Sinbad.
EnableExplicit
InitEngine3D()
InitSprite()
InitKeyboard()
Structure Vector3
X.d
Y.d
Z.d
EndStructure
Structure CharacterData
Handle.i
Node.i
Position.Vector3
EndStructure
Global.CharacterData Sinbad
Define.i CTR
Define.i Entity
Define.i Event
Define.i WinH = 720
Define.i WinW = 1280
Declare SinbadOnGround()
If OpenWindow(0, 0, 0, WinW, WinH, "3D", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, WinW, WinH)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures/", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Models/", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Packs/Sinbad", #PB_3DArchive_Zip)
Parse3DScripts()
CreateCamera(0, 0, 0, 100, 100)
CameraBackColor(0, RGB(40,60,80))
MoveCamera(0, 0, 5, 60)
CameraLookAt(0, 0, 0, 0)
CreateLight(0, RGB(200,200,200), 50, 50, 50)
LoadTexture(0, "grass.jpg")
CreateMaterial(0, TextureID(0))
LoadTexture(1, "Dirt.jpg")
CreateMaterial(1, TextureID(1))
CreatePlane(0, 100, 100, 5, 5, 10, 10)
CreateEntity(0, MeshID(0), MaterialID(0))
CreateEntityBody(0, #PB_Entity_StaticBody)
CreateCube(1, 10)
Entity = CreateEntity(#PB_Any, MeshID(1), MaterialID(1), 0, 0, -10)
CreateEntityBody(Entity, #PB_Entity_StaticBody)
With Sinbad
LoadMesh(2, "Sinbad.mesh")
\Handle = CreateEntity(#PB_Any, MeshID(2), #PB_Material_None, 0, 5, 0)
ScaleEntity(\Handle, 0.5, 0.5, 0.5)
CreateCube(3, 2)
CreateEntity(3, MeshID(3), #PB_Material_None, 0, 5, 0)
AttachEntityObject(\Handle, "Calf.R", EntityID(3))
CreateEntityBody(3, #PB_Entity_BoxBody)
RayCollide(EntityX(\Handle), EntityY(\Handle), EntityZ(\Handle), EntityX(\Handle), EntityY(\Handle)-10, EntityZ(\Handle))
\Position\X = 0
\Position\Y = PickY() + 2.45
\Position\Z = 0
MoveEntity(\Handle, \Position\X, \Position\Y, \Position\Z, #PB_Absolute)
StartEntityAnimation(\Handle, "RunBase")
EndWith
WorldDebug(#PB_World_DebugBody)
Repeat
Event = WindowEvent()
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Up)
With Sinbad
\Position\Z + 0.1
MoveEntity(\Handle, \Position\X, \Position\Y, \Position\Z, #PB_Absolute)
EndWith
EndIf
If KeyboardPushed(#PB_Key_Down)
With Sinbad
\Position\Z - 0.1
MoveEntity(\Handle, \Position\X, \Position\Y, \Position\Z, #PB_Absolute)
EndWith
EndIf
If KeyboardReleased(#PB_Key_Escape)
End
EndIf
SinbadOnGround()
CameraFollow(0, EntityID(Sinbad\Handle), 45, 5, 10, 1, 1)
RenderWorld()
FlipBuffers()
Until Event = #PB_Event_CloseWindow
EndIf
End
Procedure SinbadOnGround()
With Sinbad
RayCollide(EntityX(\Handle), EntityY(\Handle), EntityZ(\Handle), EntityX(\Handle), EntityY(\Handle)-10, EntityZ(\Handle))
\Position\Y = PickY() + 2.45
MoveEntity(\Handle, \Position\X, \Position\Y, \Position\Z, #PB_Absolute)
EndWith
EndProcedure