Difficulty with Collisions

Hi, thanks for checking this out.

I have a problem. I have two ‘player’ in my scene each set up like so: An armature which is a parent to an empty, which is a parent to a cuboid shape. (The armature is the characters rig, the cuboid represents a sword (the empty is for spawning swords))

The cuboid has a collision sensor set up looking for ‘attack’ property (the attack property is set when a player attacks), when triggered this does something (set’s ‘defend’ property to True).

Unfortunately I can’t trigger the collision sensor with a set up like this. When the cuboid (sword) shape’s have no parents the collisions work fine. Or I can get a “one way” collision if I set one sword to rigid body (or dynamic) and one to a sensor.

I need both objects to collide and activate the collision sensor whilst still being the children of an empty.

Does anyone have any suggestions? Thanks.

I assume that the issue is with the fact that you’re parenting it into non-physics objects.

I don’t know what kind of game exactly you’re making or how you should simulate melee objects for the game, but I think having them as physics objects doesn’t work too well. The sword is swung with the arm animation and when the sword collides with something the armature should react to the collision (ie stop or bounce back) but of course animations aren’t something that can have such interaction.

I haven’t really ventured onto this area too much with BGE myself (always running no physics or simplified model) but I’m sure someone can point you in right direction if we give this a slight bump?

Hi Kheetor, thanks for the bump.

You are exactly right when you say the issue is with parenting to a non-physics objects. The behaviour of the child object behaves differently, although I can still get collisions when I use Dynamic and sensor objects. I’m not trying to simulate reactions like bouncing back, but I am playing animations on collision of the child objects (Dynamic and Sensor types) and it works well enough. (I suppose you could argue that this is a type of simulation).

Well, when you spawn your sword, make sure it follows the empty’s position and orientation, instead of parent it. Otherwise, set your armature to dynamic but check the ghost radio button. I believe ghosts can detect collisions.

That sounds like a great solution, thanks! How do I get an object to follow another object? (or empty)

With python:


import bge

def <b>follow</b>(obj):
    obj     = obj.owner
    hand  = bge.logic.getCurrentScene().objects['<i>Empty</i>'] 
    obj.position= hand.position
    obj.orientation = hand.orientation

On your sword object :
Always —> [ python | Module:‘your_cript.follow’]

i would use 3 rays? leading edge middle and rear edge of sword?

this will be slightly faster(“Follow method”)

much faster if there are many objects in the scene.


if 'Target' not in own:
      scene=bge.logic.getCurrentScene()
      own['Target']=scene.objects['Empty']
else:
      t=own['Target']
      own.worldPosition=t.worldPosition
      own.worldOrientation=t.worldOrientation