Page 1 of 1

Ray cast doesn't detect a StaticMesh

Posted: Tue Jan 24, 2012 9:45 pm
by al9191
In the space I have a StaticMesh that is created from an FBX model of a tree. Collisions with the tree work fine, so it is in the space correctly.
However, when I do a ray cast in the direction of the tree. It cannot detect it, and simply returns no collisions from the ray cast result.

Code: Select all

public void rayCast(Vector3 position, Vector3 direction, float distance)
        {
            List<RayCastResult> rayCastResults = new List<RayCastResult>();
            if (space.RayCast(new Ray(position, direction), distance, RayCastFilter, rayCastResults))
            {
                var entityCollision = rayCastResults[0].HitObject as EntityCollidable;
                if (entityCollision != null)
                {
                    //DebugDisplay.update("0", entityCollision.Entity.Tag.ToString()); found it print
                }
                if (rayCastResults.Count > 1)
                {
                    var entityCollision2 = rayCastResults[1].HitObject as EntityCollidable;
                    if (entityCollision2 != null)
                    {
                        DebugDisplay.update("1", entityCollision2.Entity.Tag.ToString()); found it print. Just to make sure there isn't multiple.
                    }
                }
            }
            else
            {
                //DebugDisplay.update("SEESOMETHING", "I CANNOT SEE ANYTHING"); Not found anything.
            }
        }

        bool RayCastFilter(BroadPhaseEntry entry)
        {
            return entry != Game.getGV().Body.CollisionInformation && entry.CollisionRules.Personal <= CollisionRule.Normal;
        }
When the ray is cast in direction of the tree from very very near it, so that the ray definitely passes through the tree. It just does the print that says nothing has been found. (The else above.)
However, when the same is done for detecting a DynamicObject which is a ConvexHull created from a virus shaped model. It finds it and prints to say it is found as shown in the if above.

How come it is not detecting the StaticMesh?


*EDIT* Ok it seems to have just started detecting it. Don't know what was going on before!

Re: Ray cast doesn't detect a StaticMesh

Posted: Tue Jan 24, 2012 10:11 pm
by Norbo
Is the space.RayCast truly returning false? If so, is the collision rule set up such that it gets filtered out?

If I had to guess, I'd say the space.RayCast is returning true, but all the casts expect it to have hit an EntityCollidable. A StaticMesh is not an EntityCollidable, so the cast attempts return null. A ConvexHull.CollisionInformation is an EntityCollidable, so the analysis would find it.