Game Development Community

Is it possible to get the SceneObjects collision rectangle?

by Brandon · in Torque X 2D · 01/17/2009 (8:41 pm) · 5 replies

I'd like to handle some things based on where the object is. Is it better to just create an invisible material on the scene and handle it as an onCollision event? or Can I just get the scenObjects collision rectangle and build my own rectangle to intersect it with?

#1
01/17/2009 (9:19 pm)
Well with that said, I created a material that I wanted to handle the onCollision event, but no matter what it keeps me from entering the space even though I have resolve collision to none.

So basically I want to be able to run all around the invisible area, and handle it as if it was a collision, but not be an actual collision.

So I'm back to thinking somehow I need to access the collision rectangles and just check if they intersect. But I can't find these values in my sceneObject
#2
01/17/2009 (9:39 pm)
It sounds like you are trying to have some event happen when a player comes in contact with something, a button for instance, but at the same time you don't want the player to collide with the button. Is this an accurate assessment?

If this is the case you could do something similar to what I'm doing here. Basically you use the FindObjects method of T2DSceneGraph to locate scene objects of a certain type within a certain range of the player (or any other scene object of your choosing).
#3
01/17/2009 (10:19 pm)
This is sort of what I'm trying to do. I'm actually trying to make it to where I can have an enemy or an NPC react to me when I get close to them. So I've been trying to create an invisible sprite and setting the collision and then mounting the sprite to my NPC and have it collide with the player.

I've found that you have to mount the NPC to the invisible sprite for collision to be detected. Still having trouble accessing the objects of the NPC once the collision is detected though.

So basically I figured if I could dynamically create my own rectangle around the NPC and during the processtick of whatever component just check for a Rectangle.Intersects with the player then I can react that way.

TX has a RectangleF class, but so far the it seems all I can get access to are the world limits.
#4
01/18/2009 (8:35 am)
I can help you. I draw a rectangle to see if one of my characters has room to teleport before I move there physics.

Here is the code :)

public static class SpaceCheck
    {
        //Open Space Check, checks to see if a space is a vallid location to move a character ################################################################
        public static bool Test(float jumperPosX, float thierPosX, float posY)
        {
            float diff = Math.Abs(jumperPosX - thierPosX);
            float posX = 0.0f;

            if (jumperPosX < thierPosX)
                posX = thierPosX + (128 - diff);
            else
                posX = thierPosX - (128 - diff);

            Vector2 sp = new Vector2(posX, posY);
            Vector2 wh = new Vector2(128, 128);
            RectangleF rec = new RectangleF(sp, wh);

            List<ISceneContainerObject> foundObjects = new List<ISceneContainerObject>();
            T2DSceneGraph mySceneGraph = TorqueObjectDatabase.Instance.FindObject<T2DSceneGraph>("DefaultSceneGraph");
            mySceneGraph.FindObjects(rec, Game.Instance.ObjTypes.Ground, 0xFFFFFFFF, foundObjects);
            if (foundObjects.Count > 0)
            {
                return false;
            }
            else
            {
                List<ISceneContainerObject> foundHelpers = new List<ISceneContainerObject>();
                mySceneGraph.FindObjects(rec, Game.Instance.ObjTypes.PlayerHelper, 0xFFFFFFFF, foundHelpers);

                if (foundHelpers.Count > 1)
                    return false;
                else
                    return true;
            }

        }
    }
#5
01/18/2009 (10:02 am)
That's pretty much exactly what I was going to recommend.