Hi,
Today i started playing with physics especially collisions with the Paradox engine in a 2D sample.
I followed the documentation here about Physics to set up my sample.
I setted up a first Entity as a PhantomCollider because i only want the events to be trigerred
Then i setted up a second Entity as PhantonCollider too. In the both i checked Sprite.
I created two ColliderShapes the first one as a CapsuleColliderShape because the sprite represent my character and the second one as a Box2DColliderShape because the sprite is a simple platform. In the both i checked is2D.
First of all i declared a private variable of the type IPhysicsSystem in my Game Class
private IPhysicsSystem physicsSystem;
Then i instanciate the physicsSystem in my method LoadContent of the Game Class
physicsSystem = new Bullet2PhysicsSystem(this);
physicsSystem.PhysicsEngine.Initialize(PhysicsEngineFlags.None);
I have a class in which i initialize colliders for my both entities. The UIManager is only a class i use to show up some debug infos on the screen.
public Collider InitializeCollider() {
this.collider = this.Entity.GetOrCreate(PhysicsComponent.Key)[0].Collider;
// Link events
this.Collider.OnContactBegin += Collider_OnContactBegin;
this.Collider.OnContactChange += Collider_OnContactChange;
this.Collider.OnContactEnd += Collider_OnContactEnd;
this.Collider.OnFirstContactBegin += Collider_OnFirstContactBegin;
this.Collider.OnLastContactEnd += Collider_OnLastContactEnd;
return this.collider;
}
void Collider_OnLastContactEnd(object sender, CollisionArgs e)
{
UIManager.GetInstance().AddLine("debugTextBlock","Collider_OnLastContactEnd");
}
void Collider_OnFirstContactBegin(object sender, CollisionArgs e)
{
UIManager.GetInstance().AddLine("debugTextBlock", "Collider_OnFirstContactBegin");
}
private void Collider_OnContactEnd(object sender, CollisionArgs e)
{
UIManager.GetInstance().AddLine("debugTextBlock", "Collider_OnContactEnd");
}
private void Collider_OnContactChange(object sender, CollisionArgs e)
{
UIManager.GetInstance().AddLine("debugTextBlock", "Collider_OnContactChange");
}
private void Collider_OnContactBegin(object sender, CollisionArgs e)
{
UIManager.GetInstance().AddLine("debugTextBlock", "Collider_OnContactBegin");
}
Then in my game Class i add the colliders to the physicsEngine.
this.physicsSystem.PhysicsEngine.AddCollider(this.entity.InitializeCollider());
this.physicsSystem.PhysicsEngine.AddCollider(this.plateforme.InitializeCollider());
But my problem is that events are always trigerred even if my entites aren’t in contact.
Did i do something wrong ?