Page 1 of 1

RayCast wheels

Posted: Tue Dec 16, 2008 8:41 pm
by goldsword
I'm having a problem with ray cast wheel when trying to actually use a physical body for the wheel... The problem is the body will be detected by the raycast and supporting the vehicle and there is no way to tell the wheel to exclude certain objects afaik. The reason I want a body for the wheel is to detect collision from other sources such as well you guessed, bullets :)

Re: RayCast wheels

Posted: Tue Dec 16, 2008 9:19 pm
by Zukarakox
Use the raycast method that includes all of the hits:

Code: Select all

List<Entity> hitE = new List<Entity>();
List<Vector3> hitL = new List<Vector3>();
List<Vector3> hitN = new List<Vector3>();
List<float> hitT = new List<float>();
space.rayCast(Cam.position, Cam.Unproject(), 20f, false, hitE, hitL, hitN, hitT);
Then iterate through all of the hit entities, finding the hit with the lowest time (toi) that is not your wheel.

Code: Select all

            x = -1;
            for (int y = 0; y < hitE.Count; y++)
            {
                if (hitE[y] != wheel)
                {
                    if (x != -1)
                    {
                        if (hitT[y] < hitT[x])
                        {
                            x = y;
                        }
                    }
                    else
                    {
                        x = y;
                    }
                }
            }
Then use x to reference which it hit.

Code: Select all

            if (x != -1)
            {//Do stuff here!
            }

Sorry for the weird indentation on the code snippets, I copied it from a peice of code inside a method.

Re: RayCast wheels

Posted: Tue Dec 16, 2008 9:38 pm
by goldsword
Maybe I wasnt clear, but I mean the ray cast performed "under the hood" by the BEPYphysics.RayCastWheel

Re: RayCast wheels

Posted: Tue Dec 16, 2008 11:52 pm
by Norbo
I believe the wheel will ignore entities that have their isDetector flag equal to true, but I'm currently away from the code. Detectors will still generate contacts and such (and throw collision events), but will not undergo collision response. Wheel support filtering could use some improvement. This laptop is about to run out of batteries so I'll check back later.

Re: RayCast wheels

Posted: Wed Dec 17, 2008 8:20 pm
by Zukarakox
Well then, I have no idea! Never used the wheels included with physics.