Multiple Items in the same place
by Steve Lamperti · in Torque Game Engine · 11/16/2004 (8:31 am) · 10 replies
I have a situation where items can pop into existence at certain locations. The problem I am having with this is that if an item appears, and there is already an item present in that location, or close enough so that there is an overlap, I have a collision situation where neither of the items can move.
I've thought of a couple possible solutions to this, but I'm not sure which is best, and I was wondering if anyone had any suggestions.
1) Check for a collision in onAdd, and move the new item a certain distance (up? or a random direction?)
2) Turn off collision in onAdd, and then turn it back on a little later. (I'm not sure when to turn it back on. Perhaps the first time I try to move the object, and it is not in a collision situation.)
3) Change the collision code so that a collistion where the edges collide is a collision, but a collision where the items are in the same space is not. (I'm not sure how to do this, or even if it's doable.)
If anyone has any suggestions, or knows of any resources that address any of these questions, I would appreciate hearing about them.
I've thought of a couple possible solutions to this, but I'm not sure which is best, and I was wondering if anyone had any suggestions.
1) Check for a collision in onAdd, and move the new item a certain distance (up? or a random direction?)
2) Turn off collision in onAdd, and then turn it back on a little later. (I'm not sure when to turn it back on. Perhaps the first time I try to move the object, and it is not in a collision situation.)
3) Change the collision code so that a collistion where the edges collide is a collision, but a collision where the items are in the same space is not. (I'm not sure how to do this, or even if it's doable.)
If anyone has any suggestions, or knows of any resources that address any of these questions, I would appreciate hearing about them.
#2
You probably don't want to go changing a major system such as collisions for something that can be adjusted otherwise, but that's just a thought!
11/16/2004 (3:04 pm)
Many times in this situation folks will give a sphere around the desired location where the object/player can appear, very similar to how the spawn spheres work when the player enters the game.You probably don't want to go changing a major system such as collisions for something that can be adjusted otherwise, but that's just a thought!
#3
11/16/2004 (3:49 pm)
Dont spawn 2 things in one place. try this approach. you can schedule a function to check if the spawn point is clear by using a radius search. if its not clear, reschedule some time later. use a few spawn spheres so that people don't have to wait too long.
#4
Lets say you wanted 5 ammo clips to ALWAYS be availalbe in a certain area for players to pick up. When it comes time to check for spawn, do the radius search and count the clips that are found, if you need to spawn one or more, use the randomized area to spawn it. Then in your "AmmoClip::onCollision()" function, if the %col class is the same as the %obj class, just delete the newly spawned clip (%col) so that you dont get the collision situation that is troubling you.
11/17/2004 (4:26 am)
Depending on the objects you are spawning and their size, I would probably use a randomized area like Stephen suggested, but Robert's suggestion is also an excellent one. Not knowing what your situation is, you could even combine the two into one function.Lets say you wanted 5 ammo clips to ALWAYS be availalbe in a certain area for players to pick up. When it comes time to check for spawn, do the radius search and count the clips that are found, if you need to spawn one or more, use the randomized area to spawn it. Then in your "AmmoClip::onCollision()" function, if the %col class is the same as the %obj class, just delete the newly spawned clip (%col) so that you dont get the collision situation that is troubling you.
#5
@Robert
Where should I look in the code to look for how to do a radius search? It's clear that no matter what solution I try to implement, I need to know if an item is already present, and some existing code that will check that will help me. (I don't want to have to copy the collision code for the object into onAdd.) Just the name of a routine that I should be looking at as a starting point would be helpful.
11/17/2004 (7:27 am)
Thanks for the responses. I have a slightly unusual situation in that I am not building a game, but rather a 3D model of business processes, so I have different requirements. This is not a spawn point for items, or enemies, but rather the starting point of a conveyor belt, or something like that. Part of what this means is that each item is important, and the position of each item is also quite important. Also, the timing of when each item arrives is a factor. This puts a damper on several of the suggestions. I probably should have described this up front, as it puts a quite different complexion on my question.@Robert
Where should I look in the code to look for how to do a radius search? It's clear that no matter what solution I try to implement, I need to know if an item is already present, and some existing code that will check that will help me. (I don't want to have to copy the collision code for the object into onAdd.) Just the name of a routine that I should be looking at as a starting point would be helpful.
#6
11/17/2004 (7:33 am)
If you are looking at placing an item "on" the conveyor belt for example, you may want to at least experiment with spawning the item -above- the belt, and letting game physics drop it into place. You may be able to use that technique, refined for much closer locations, for other scenarios.
#7
Thanks for the response, That may be a good suggestion. I was thinking about my #2 idea above, and the problem with it is if I spawn two or more items in the same place, and they are then moved together, they will not ever turn on their collision, and they will proceed to travel through everything in their path. Part of the reason I wasn't sure about the creating above and dropping is that I currently have gravity turned off for the type of items that are travelling along the belt, but perhaps turning gravity back on, and creating the items above the creation point is correct.
11/17/2004 (7:46 am)
@stephen, Thanks for the response, That may be a good suggestion. I was thinking about my #2 idea above, and the problem with it is if I spawn two or more items in the same place, and they are then moved together, they will not ever turn on their collision, and they will proceed to travel through everything in their path. Part of the reason I wasn't sure about the creating above and dropping is that I currently have gravity turned off for the type of items that are travelling along the belt, but perhaps turning gravity back on, and creating the items above the creation point is correct.
#8
11/17/2004 (8:48 am)
Well, you'll need gravity on simply to have a friction impulse force (and even then I imagine that will need some extensive tweaking) for the objects to move along your conveyor belt (note: this is theory, I've never done anything like this before in TGE) in any case, so you may want to think about it from that angle.
#9
This is probably getting too specific to my project to be helpful to other readers of this forum, so I'll just continue to try to resolve it here.
Thanks for all the input.
11/17/2004 (11:04 am)
My ExtendItem that is the object that is travelling along the conveyors is already moving via a mechanism that I have added to the C++ code, so it is already moving without gravity turned on. The down side to turning gravity on, is that we currently have these items moving along through space at the height of the conveyor belt, whether or not the belt is there. This is kind of convenient, as it means we can just place arrival and exit locations without worrying about placing conveyors along the path.This is probably getting too specific to my project to be helpful to other readers of this forum, so I'll just continue to try to resolve it here.
Thanks for all the input.
#10
With the additional info you provided, that would make more sense in any case. You shouldn't add another item to your conveyor belt if there isn't any room, so you should wait a bit until the conveyor belt is ready.
You may even want to make it so that your conveyor belt can "announce" that it is ready for a new item, and trigger your object spawner to create it then, instead of trying to jam in a new item before the belt is ready.
11/17/2004 (11:10 am)
Well, in that case, I thnk the solution expressed above is your best bet: check to see if an object is already there, and if so, use .schedule to delay the creation of your current one for a few seconds, and then try again.With the additional info you provided, that would make more sense in any case. You shouldn't add another item to your conveyor belt if there isn't any room, so you should wait a bit until the conveyor belt is ready.
You may even want to make it so that your conveyor belt can "announce" that it is ready for a new item, and trigger your object spawner to create it then, instead of trying to jam in a new item before the belt is ready.
Torque Owner Steve Lamperti
Imagine That!