Checking for non-collision
by Shiraz · in Torque X 2D · 02/24/2007 (1:35 am) · 10 replies
I have a character that is constantly dropping sprites for other characters to pick up. However, I don't want the dropped sprites to start piling up on each other. I figure the best way to do this is to check that the dropper isn't colliding with the droppee type. So is there a way to check that I'm not colliding with something?
If not, can anyone reccommend a workaround? Currently the character is destroying any sprites it collides with while dropping new ones behind it, but I think this is an process heavy solution.
Thanks.
If not, can anyone reccommend a workaround? Currently the character is destroying any sprites it collides with while dropping new ones behind it, but I think this is an process heavy solution.
Thanks.
About the author
#2
02/26/2007 (3:51 pm)
Because then I'd be doing the process of creating them, checking collision and then deleting them right away which is what I'm trying to avoid. I just want to do, am I touching anything? no? create.
#3
EDIT: Now that I look at it, it looks like triggers are T2DTriggerComponents.
02/26/2007 (4:50 pm)
The only other way I can think of off the top of my head would be to use T2DTriggers which have an onLeave delegate or override I'm not sure where you could just set a variable that says they're not colliding. That would be kind of a hack and there would some finicky stuff to work out e.g. colliding with two at the same time. I know there was a castCollision() method in TGB but I'm not sure if it migrated into TorqueX.EDIT: Now that I look at it, it looks like triggers are T2DTriggerComponents.
#4

02/27/2007 (6:50 am)
I wouldn't use a trigger for this, if all you want to do is determine if you should create a box or not based on the location you try to create it. You should build a custom component which just does a simple location check. You would search the TODB for anything that the new object would hit and if found, move on, if not then create.
#5
It sounds like you want to check for collision against the PLAYER to see if the space is open? That's what your original question sounds like. Is that correct?
02/27/2007 (8:09 am)
@ShirazIt sounds like you want to check for collision against the PLAYER to see if the space is open? That's what your original question sounds like. Is that correct?
#6

02/27/2007 (9:27 am)
No, he doesn't want to check for collision but just if something exists. If something exists in a spot where he'd want to write a new object, he doesn't want to write that object, but if nothing exists, then write the object.
#7
I may have a workaround, though, if this isn't possible. I can create a 2D boolean array mapping to the screen and mark a cell with slime each time I create it. Then the ghost just has to check its position against the array to see if it's ok to create slime. Sound feasible?
02/27/2007 (11:53 am)
Yeah. K, here's what's happening in the game. A bunch of ghosts are running around a house leaving a trail of slime behind them. You have to vacuum up the slime to keep the house clean. Originally I didn't care if the ghosts just let slime pile up, but in actual play the act of detecting and destroying a lot of slime could grind the play to a halt in some areas. Now this COULD be part of the gameplay. That nasty stain that just won't come out. But the ghosts tend to quickly overwhelm the player in those situations. SO, I want to keep the slime from piling up and that means checking if there's already slime there.I may have a workaround, though, if this isn't possible. I can create a 2D boolean array mapping to the screen and mark a cell with slime each time I create it. Then the ghost just has to check its position against the array to see if it's ok to create slime. Sound feasible?
#8
02/27/2007 (12:02 pm)
@Shiraz - have you tried the FindObjects method of T2DSceneGraph?
#9
02/27/2007 (6:10 pm)
Never heard of it. What does it do? Well, I'm guessing it finds objects, but how does it work? :-)
#10
I'm not sure if it will be less computationally intensive than your current system of destroying on collision, but it might be a bit more elegant to use this to check before you drop. I find the syntax a little bit cumbersome, but this is one of the few ways to get information back out of the scenegraph in Torque X.
02/27/2007 (6:36 pm)
It puts objects from a particular area of the scenegraph (that match the object type and layer you specify) into a list. It's used by trigger components to see if objects are inside the trigger area, and I think it may be used by the collision system, too. If you're familiar with TGB, it's analagous to the pickRect function there.List<ISceneContainerObject> _nearbyObjects = new List<ISceneContainerObject>(); _nearbyObjects.Clear(); RectangleF SearchArea = new RectangleF(SceneObject.Position, new Vector2(_width, _height)); T2DSceneGraph.Instance.FindObjects(SearchArea, TorqueObjectType.AllObjects, (uint)0xFFFFFFFF, _nearbyObjects);
I'm not sure if it will be less computationally intensive than your current system of destroying on collision, but it might be a bit more elegant to use this to check before you drop. I find the syntax a little bit cumbersome, but this is one of the few ways to get information back out of the scenegraph in Torque X.
Torque 3D Owner Jonathon Stevens