General Collisions questions
by Dannon Gruver · in Torque X 2D · 02/02/2007 (6:49 am) · 4 replies
For the last 2 days I've been trying to get a simple collision to occur. Feeling pretty silly by now I've decided to ask.
So here's my example. Inside TorqueGame's BeginRun() I've got the following code that creates 2 static sprites and sets the 2nd sprite to collide with the 1st:
T2DStaticSprite a1 = new T2DStaticSprite();
a1.ObjectType = TorqueObjectDatabase.Instance.GetObjectType("E1");
a1.Material = (RenderMaterial)TorqueObjectDatabase.Instance.FindObject("GGLogoMaterial");
a1.Name = "E1name";
a1.Size = new Vector2(20, 20);
a1.Layer = 3;
T2DPolyImage image = new T2DPolyImage();
image.CollisionPolyPrimitive = 4;
a1.Collision.InstallImage(image);
a1.Collision.RenderCollisionBounds = true;
TorqueObjectDatabase.Instance.Register(a1);
a1.Position = new Vector2(3, 0);
T2DStaticSprite a2 = new T2DStaticSprite();
a2.ObjectType = TorqueObjectDatabase.Instance.GetObjectType("E2");
a2.Material = (RenderMaterial)TorqueObjectDatabase.Instance.FindObject("GGLogoMaterial");
a2.Name = "E2name";
a2.Size = new Vector2(20, 20);
a2.Layer = 3;
T2DPolyImage image2 = new T2DPolyImage();
image2.CollisionPolyPrimitive = 4;
a2.Collision.InstallImage(image2);
a2.Collision.OnCollision = this.cc;
a2.Collision.RenderCollisionBounds = true;
a2.Collision.CollidesWith = a1.ObjectType;
a2.CollisionsEnabled = true;
TorqueObjectDatabase.Instance.Register(a2);
...and I've also got the following event handler...
public void cc(T2DSceneObject ourObject, T2DSceneObject theirObject, T2DCollisionInfo info, ref T2DResolveCollisionDelegate resolve, ref T2DPhysicsMaterial physicsMaterial)
{
throw new Exception("COLLIDED");
}
I compile & run but no exception is thrown. Both collision polygons (squares) are shown and clearly overlap. I've tried turning on collisions for both sprites. I've also tried setting the physics' material & physic's collision response on each static sprite. Still no exception.
Another related question is: What are the TorqueObjectTypes? Are these equivalent to Torque Game Builder's graph groups?
So here's my example. Inside TorqueGame's BeginRun() I've got the following code that creates 2 static sprites and sets the 2nd sprite to collide with the 1st:
T2DStaticSprite a1 = new T2DStaticSprite();
a1.ObjectType = TorqueObjectDatabase.Instance.GetObjectType("E1");
a1.Material = (RenderMaterial)TorqueObjectDatabase.Instance.FindObject("GGLogoMaterial");
a1.Name = "E1name";
a1.Size = new Vector2(20, 20);
a1.Layer = 3;
T2DPolyImage image = new T2DPolyImage();
image.CollisionPolyPrimitive = 4;
a1.Collision.InstallImage(image);
a1.Collision.RenderCollisionBounds = true;
TorqueObjectDatabase.Instance.Register(a1);
a1.Position = new Vector2(3, 0);
T2DStaticSprite a2 = new T2DStaticSprite();
a2.ObjectType = TorqueObjectDatabase.Instance.GetObjectType("E2");
a2.Material = (RenderMaterial)TorqueObjectDatabase.Instance.FindObject("GGLogoMaterial");
a2.Name = "E2name";
a2.Size = new Vector2(20, 20);
a2.Layer = 3;
T2DPolyImage image2 = new T2DPolyImage();
image2.CollisionPolyPrimitive = 4;
a2.Collision.InstallImage(image2);
a2.Collision.OnCollision = this.cc;
a2.Collision.RenderCollisionBounds = true;
a2.Collision.CollidesWith = a1.ObjectType;
a2.CollisionsEnabled = true;
TorqueObjectDatabase.Instance.Register(a2);
...and I've also got the following event handler...
public void cc(T2DSceneObject ourObject, T2DSceneObject theirObject, T2DCollisionInfo info, ref T2DResolveCollisionDelegate resolve, ref T2DPhysicsMaterial physicsMaterial)
{
throw new Exception("COLLIDED");
}
I compile & run but no exception is thrown. Both collision polygons (squares) are shown and clearly overlap. I've tried turning on collisions for both sprites. I've also tried setting the physics' material & physic's collision response on each static sprite. Still no exception.
Another related question is: What are the TorqueObjectTypes? Are these equivalent to Torque Game Builder's graph groups?
#2
Whoops, looks like the OnCollision event handler will only get called if your objects run into each other (duh!). My 2 objects were created at the center of the screen and didn't move. So even though they overlapped they still didn't collide(?). As soon as I seperated them like bad children and sent 1 crashing into the other, the OnCollision event fired. JOY!
02/02/2007 (8:28 pm)
Thanks Jonathon!!Whoops, looks like the OnCollision event handler will only get called if your objects run into each other (duh!). My 2 objects were created at the center of the screen and didn't move. So even though they overlapped they still didn't collide(?). As soon as I seperated them like bad children and sent 1 crashing into the other, the OnCollision event fired. JOY!
#3
02/02/2007 (8:28 pm)
Good deal =)
#4
02/03/2007 (12:56 am)
By default, objects that are not moving do not test for collision. That's why you were seeing that behavior.
Torque 3D Owner Jonathon Stevens