EnableCollisionListening

Apr 19, 2012 at 11:08 AM

Hi !

Why ' this.actor.EnableCollisionListening() ' not work?

Here are the lines of code that added to TerrainPhysicsComponent.cs :

private void CreateHeightfieldActor(IPhysicsScene PhysicsScene, float[,] heightData, float scaleFactor)
{
             .......

            if (this.actor != null)
            {
                this.actor.EnableCollisionListening();
            }
 }

Thanks

Coordinator
Apr 19, 2012 at 9:29 PM
Are you trying to receive a callback whenever something collides with terrain? If that is the case the terrain Entity should already be receiving collision messages from any dynamic physics actor that collides with it. Reference the file CollisionTriggerComponent, line 235, the message type 'Collision', that message will be sent to your Terrain Entity whenever something collides with it. You can listen for that message in the TerrainComponent message handler.



On Apr 19, 2012, at 4:09 AM, "smohammad59v" <notifications@codeplex.com> wrote:

From: smohammad59v

Hi !

Why ' this.actor.EnableCollisionListening() ' not work?

Here are the lines of code that added to TerrainPhysicsComponent.cs :

private void CreateHeightfieldActor(IPhysicsScene PhysicsScene, float[,] heightData, float scaleFactor)
{
.......

if (this.actor != null)
{
this.actor.EnableCollisionListening();
}
}

Thanks

Apr 24, 2012 at 6:27 AM

Hi !
I modified " PhysicComponent.CS " :

protected virtual void CreateActor(IPhysicsScene PhysicsScene)
{
        ...
        if (this.actor != null)
        {
                this.actor.EnableCollisionListening();
         }
}      

public override bool ExecuteMessage(IMessage message)
{
         ....
         case MessageType.Collision:
         {
                 //My Code
          }
          return true;
         ....
}

 

and Create Entityies :

BaseEntity entity_1 = new BaseEntity(this.game, position_1, Matrix.Identity,1.0f);
PhysicsComponent phyCom_1 = new PhysicsComponent(entity_1, ShapeType.Box, 1.0f, true);

BaseEntity entity_2 = new BaseEntity(this.game, position_2, Matrix.Identity,1.0f);
PhysicsComponent phyCom_2 = new PhysicsComponent(entity_2, ShapeType.Box, 1.0f, true);

but when "entity_1" collided with "entity_2" , "Collision Message" not received

Thanks

Coordinator
May 2, 2012 at 5:52 AM

Currently the basic rigid bodies are not setup to listen to collisions between one another. This is because collisions between two dynamic rigid bodies can occur many times in a short time span, imagine for example someone breaking a rack of pool balls, as soon as the que ball hits you'll have hundreds of collisions between the group of balls.

You can enable this if you would like. Just fire a MsgListenForCollision message to the entity that you want to listen for collision messages. Make sure you send the message after the entity has a physics component.

For example:

BaseEntity entity_1 = new BaseEntity(this.game, position_1, Matrix.Identity,1.0f);
PhysicsComponent phyCom_1 = new PhysicsComponent(entity_1, ShapeType.Box, 1.0f, true);

MsgListenForCollision msgListen = ObjectPool.Aquire<MsgListenForCollision>();
msgListen.ListenForCollisions = true;
msgListen.UniqueTarget = entity_1.UniqueID;
this.game.SendMessage(msgListen); 

 

Do this for both entities and you should receive collision messages for each I believe.