RayCast wheels

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
goldsword
Posts: 18
Joined: Fri Dec 05, 2008 8:46 pm

RayCast wheels

Post 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 :)
User avatar
Zukarakox
Not a Site Admin
Posts: 426
Joined: Mon Jul 10, 2006 4:28 am

Re: RayCast wheels

Post 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.
i has multiple toes
goldsword
Posts: 18
Joined: Fri Dec 05, 2008 8:46 pm

Re: RayCast wheels

Post by goldsword »

Maybe I wasnt clear, but I mean the ray cast performed "under the hood" by the BEPYphysics.RayCastWheel
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: RayCast wheels

Post 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.
User avatar
Zukarakox
Not a Site Admin
Posts: 426
Joined: Mon Jul 10, 2006 4:28 am

Re: RayCast wheels

Post by Zukarakox »

Well then, I have no idea! Never used the wheels included with physics.
i has multiple toes
Post Reply