Page 1 of 1

Wheels EventManager

Posted: Thu Oct 07, 2010 11:11 am
by Pedro
Hi, i got some difficulties with the Wheels.
Ok i have a vehicle and i want to know when each wheel have a collision with the ground or not.
Iam using the WheelShape.Detector property.

Code: Select all

for (var k = 0; k < 4; k++)
            {
                Vehicle.Wheels[k].Shape.Detector.Tag = string.Format("Wheel_{0}", k);
                Vehicle.Wheels[k].Shape.Detector.EventManager.InitialCollisionDetected += HandleCollision;
                Vehicle.Wheels[k].Shape.Detector.EventManager.CollisionEnded += HandleEndCollision;
            }
But this code doesn't work :cry:
Thanks for helping...; and sorry for my bad English

Re: Wheels EventManager

Posted: Thu Oct 07, 2010 6:49 pm
by Norbo
The Detector does not create contacts with anything, so it will never actually fire contact-related events like InitialCollisionDetected or CollisionEnded. It will, however, fire CollisionPair related events.

CollisionPair events won't tell you exactly when the ray hits something, but rather when the Detector's AABB overlaps with other entities' AABB's.

You can also check the Vehicle's support entities each frame through each Wheel's SupportingEntity property.

Re: Wheels EventManager

Posted: Thu Oct 07, 2010 7:57 pm
by Pedro
Thanks. i will test the SupportingEntity

Re: Wheels EventManager

Posted: Thu Oct 07, 2010 8:11 pm
by Pedro
oops, when i try to use the SupportingEntity in the update method, i get "Object reference not set to an instance of an object."
wheel.SupportingEntity = null

the code is in the update method

Code: Select all

foreach (var wheel in Vehicle.Wheels)
                {
                    wheel.SupportingEntity.EventManager.InitialCollisionDetected += HandleCollision;
                    wheel.SupportingEntity.EventManager.CollisionEnded += HandleEndCollision;
                }

Re: Wheels EventManager

Posted: Thu Oct 07, 2010 8:26 pm
by Pedro
Oh, i fixe it.
Its just test if the supportingEntity is null or not "Collision or not"
Thanks Norbo, you are a life saver.