Changing CollidesWith at Runtime
by Tony Pitman · in Torque X 2D · 05/22/2010 (8:27 pm) · 4 replies
I would like to change the object types that my player object collides with during runtime. Basically I am poping up a dialog on top of my main scene during play. At this point I am moving a different static sprite in front of the main background sprite.
The main background sprite has scene objects on it that the player collides with. This is how I limit where the player can move. These scene objects are of type Ship.
When I move the dialog scene object with its mounted scene sprite objects in front of the ship I want the player object to ignore all of the type Ship objects and only collide with the new DialogBorder type scene objects.
My player has a T2DCollisionComponent on it. By default I have set it to collide with objects of type Ship. When the dialog appears I want to change that so that it does NOT collide with type Ship objects, but then ADD type DialogBorder to the list of CollidesWith.
I know I could just make it collide with both and then have a component that determines the mode (dialog or ship) and then collide or not, but it seems like there should be a way to modify what an object collides with at runtime and that would be easier.
Can someone tell me how to do it?
The main background sprite has scene objects on it that the player collides with. This is how I limit where the player can move. These scene objects are of type Ship.
When I move the dialog scene object with its mounted scene sprite objects in front of the ship I want the player object to ignore all of the type Ship objects and only collide with the new DialogBorder type scene objects.
My player has a T2DCollisionComponent on it. By default I have set it to collide with objects of type Ship. When the dialog appears I want to change that so that it does NOT collide with type Ship objects, but then ADD type DialogBorder to the list of CollidesWith.
I know I could just make it collide with both and then have a component that determines the mode (dialog or ship) and then collide or not, but it seems like there should be a way to modify what an object collides with at runtime and that would be easier.
Can someone tell me how to do it?
About the author
#2
12/07/2010 (2:20 pm)
Hey, thanks for that 6 months later. It came in quite handy.
#3
12/07/2010 (2:39 pm)
Awesome, glad it helped. Sharing the things we learn is worth more to us in the end than trying to keep all the knowledge to ourselves.
#4
12/07/2010 (2:46 pm)
Totally. I've had a rough time figuring out how to manipulate tiles at runtime, and this was one of the last parts of the puzzle missing. Hopefully I can help someone else ;)
Torque Owner Tony Pitman
Default Studio Name
T2DCollisionComponent collision = Owner.Components.FindComponent<T2DCollisionComponent>(); if (collision != null) { collision.CollidesWith -= TorqueObjectDatabase.Instance.GetObjectType("Ship"); collision.CollidesWith += TorqueObjectDatabase.Instance.GetObjectType("DialogBorder"); } T2DTriggerComponent trigger = Owner.Components.FindComponent<T2DTriggerComponent>(); if (trigger != null) { trigger.CollidesWith -= TorqueObjectDatabase.Instance.GetObjectType("Trigger"); trigger.CollidesWith += TorqueObjectDatabase.Instance.GetObjectType("DialogTrigger"); }