Thank you for your reply Joh
The character does not have a body itself. I create bodies in the code and attach them to the bones (maybe I will create a little editor for this). I think I'm going to attach a simple body to most of the bones, so the ball can collide with everything and I am able to tell which part of the character was hit.
In the mean time I found out that the problem is TMesh.Copy. I set up the bodies for the loaded mesh and was working with a copy of this mesh all the time, because it's a multiplayer game and each player instance uses a copy of the mesh. It seems that TMesh.Copy does not copy the GravityMode for the children. When I set the GravityMode of the copy to 0 it was working. Is this a bug or normal behavior?
But now I have another problem: I use no response collisions, but whenever a collision occurs the body (cylinder) rotates, although there is no code in the collision callback at all. The ball behaves correctly, it does not move or rotate.
Thank you for your tip with the joints, I will have a look at those.
I made a little test program with the same situation. Here are some screenshots:
http://zehr.de/screenshots/screenshot1.png
http://zehr.de/screenshots/screenshot2.png
http://zehr.de/screenshots/screenshot3.png
Here is the source code and the mesh which was used:
http://zehr.de/downloads/collision_test.zip
SuperStrict
Framework leadwerks.engine
GCSetMode(2)
RegisterAbstractPath("")
'Collision types
Const COL_PLAYER:Int = 1
Const COL_WORLD:Int = 2
Const COL_BALL:Int = 3
'Initialize graphics and world
Graphics(800, 600, 0, 0)
Local world:TWorld = CreateWorld()
Local gbuffer:TBuffer = CreateBuffer(800, 600, BUFFER_COLOR | BUFFER_NORMAL | BUFFER_DEPTH)
'Create a camera
Local cam:TCamera = CreateCamera()
cam.SetPosition([0.0, 5.0, -10.0])
cam.SetRotation([10.0, 0.0, 0.0])
CameraClearColor(cam, Vec4(0.5, 0.5, 0.5, 1.0))
'Load the mesh
Local mesh:TMesh = LoadMesh("abstract::dummy.gmf")
mesh.SetPosition([- 0.5, 0.0, 10.0])
'Find the left lower leg bone of the mesh
Local lower_leg_l:TBone = TBone(mesh.FindChild("LowerLeg_L"))
'Create a body (for leg to ball collision)
Local body:TBody = CreateBodyCylinder(0.5, 2, lower_leg_l)
body.SetCollisionType(COL_PLAYER)
body.SetGravityMode(0)
body.SetMass(1)
body.SetRotation([90.0, 90.0, 0.0])
body.Move([0.0, -1.0, 0.0], 1)
body.SetCallback(OnCollision, ENTITYCALLBACK_COLLISION)
'Copy the whole mesh + body
Local mesh_copy:TMesh = mesh.Copy()
mesh_copy.SetPosition([3.0, 0.0, 10.0])
'---- Set GravityMode again on the copy... (bug?) ------------------
Local leg:TBone = TBone(mesh_copy.FindChild("LowerLeg_L"))
TBody(leg.GetChild(2)).SetGravityMode(0)
'-------------------------------------------------------------------
'Create a ground body
Local ground:TBody = CreateBodyBox(100, 0.5, 100)
ground.SetCollisionType(COL_WORLD)
ground.SetPosition([0.0, -0.5, 10.0])
'Create a ball (sphere)
Local ball:TBody = CreateBodySphere(0.5)
ball.SetCollisionType(COL_BALL)
ball.SetPosition([0.0, 2.0, 0.0])
ball.SetMass(1)
'Let the ball collide with the ground (works fine)
Collisions(COL_BALL, COL_WORLD, 1)
'Let the player collide with the ball
Collisions(COL_PLAYER, COL_BALL, 2)
'Animation frame used to animate both meshes
Local animFrame:Float = 0
'Use wireframe and debug physics
AmbientLight([0.8, 0.8, 0.8])
WireFrame(1)
DebugPhysics(1)
HideMouse()
MoveMouse(400, 300)
Repeat
UpdateAppTime()
'Use W, S, A and D to move the camera
If KeyDown(KEY_W) Then
cam.Move([0.0, 0.0, 0.1])
ElseIf KeyDown(KEY_S) Then
cam.Move([0.0, 0.0, -0.1])
End If
If KeyDown(KEY_A) Then
cam.Move([- 0.1, 0.0, 0.0])
ElseIf KeyDown(KEY_D) Then
cam.Move([0.1, 0.0, 0.0])
End If
'Use left and right arrows to animate and move both meshes
If KeyDown(KEY_LEFT) Then
animFrame:-AppSpeed()
If animFrame < 0 Then
animFrame = 148 + animFrame
End If
animFrame = animFrame Mod 148
mesh.Move([0.0, 0.0, 0.1])
mesh_copy.Move([0.0, 0.0, 0.1])
ElseIf KeyDown(KEY_RIGHT) Then
animFrame:+AppSpeed()
animFrame = animFrame Mod 148
mesh.Move([0.0, 0.0, -0.1])
mesh_copy.Move([0.0, 0.0, -0.1])
End If
'Animate both meshes with the current frame
mesh.Animate(animFrame)
mesh_copy.Animate(animFrame)
'Rotate the camera acording to the mouse movement
Local mx:Float = MouseX() - 400
Local my:Float = MouseY() - 300
MoveMouse(400, 300)
Local rot:TVec3 = Vec3(cam.rotation.x + my / 5.0, cam.rotation.y - mx / 5.0, cam.rotation.z)
cam.SetRotation(rot)
UpdateWorld(AppSpeed())
SetBuffer(gbuffer)
RenderWorld()
SetBuffer(BackBuffer())
RenderLights(gbuffer)
Flip 1
Until KeyHit(KEY_ESCAPE)
ClearWorld()
EndGraphics()
GCCollect()
End
'Collision callback
Function OnCollision(e1:TEntity, e2:TEntity, pos:TVec3, normal:TVec3, force:TVec3, speed:Float)
DebugLog("Collision")
End Function
Thanks