Triggers for projectiles?
by Nathan Snell · in Torque Game Engine · 09/23/2005 (10:40 am) · 4 replies
I am trying to make it so projectiles "activate" triggers like players do. I've searched around the forums and such and came across this thread: http://www.garagegames.com/mg/forums/result.thread.php?qt=29350
which had some discussion about it.
Unfortunately, i'm no TGE guru, nor a C++ guru so this is a bit more difficult of a task for me to do... none the less I'd like to complete it. According to the thread mentioned above, the projectile needs its own polyList and castRay. Well, obviously the projectile has castRay, but I don't quite get why it needs the PolyList, or how/why, once i've added a polylist function (which i have) to get it to correspond or work with the projectile code (as far as checking triggers go).
Additionally, I am not sure whether I should be checking in the Projectile::processTick (since it's utilizing castRay there) or in Projectile::onCollision.
I have made some modifications to the projectile code, but it still doesn't work (I think im missing the factor that links it all together).
Also, what exactly does the following do?
Any help with this would be hugely appreciated!
which had some discussion about it.
Unfortunately, i'm no TGE guru, nor a C++ guru so this is a bit more difficult of a task for me to do... none the less I'd like to complete it. According to the thread mentioned above, the projectile needs its own polyList and castRay. Well, obviously the projectile has castRay, but I don't quite get why it needs the PolyList, or how/why, once i've added a polylist function (which i have) to get it to correspond or work with the projectile code (as far as checking triggers go).
Additionally, I am not sure whether I should be checking in the Projectile::processTick (since it's utilizing castRay there) or in Projectile::onCollision.
I have made some modifications to the projectile code, but it still doesn't work (I think im missing the factor that links it all together).
Also, what exactly does the following do?
Trigger* pTrigger = static_cast<Trigger*>(rInfo.object);
pTrigger->potentialEnterObject(this);Any help with this would be hugely appreciated!
About the author
#2
then it runs the funciton "potentialEnterObject(this)" on the trigger specified passing "this" which is the object calling that function
here is that function attached to the trigger
which first loops through mObjects to see if already on the list as an entered object... if not it then checks if the object is within the trigger, if so it adds it the objects list of whats in the trigger (for the tick callback I assume) then executes the on enter callback
09/23/2005 (11:31 am)
Creates pTrigger as a pointer to a Trigger object you specify in "rInfo.object"... then it runs the funciton "potentialEnterObject(this)" on the trigger specified passing "this" which is the object calling that function
here is that function attached to the trigger
void Trigger::potentialEnterObject(GameBase* enter)
{
AssertFatal(isServerObject(), "Error, should never be called on the client!");
for (U32 i = 0; i < mObjects.size(); i++) {
if (mObjects[i] == enter)
return;
}
if (testObject(enter) == true) {
mObjects.push_back(enter);
deleteNotify(enter);
Con::executef(mDataBlock, 3, "onEnterTrigger", scriptThis(), Con::getIntArg(enter->getId()));
}
}which first loops through mObjects to see if already on the list as an entered object... if not it then checks if the object is within the trigger, if so it adds it the objects list of whats in the trigger (for the tick callback I assume) then executes the on enter callback
#3
Still having trouble with this... can anyone explain the process which occurs from the player moving to the trigger entry?
I understand that every tick the findContact function is ran for the player, but what I don't get is how the polyList is used and where the variables are coming from. I'm unsure of the usage of the buildPolyList for the player, and whether the polyList information at the beginning of the findContact function is the "magic" that makes it all work.
Is the polyList for the trigger or the projectile?
As far as I understand it:
Player Moves -> findContact ran -> Somehow a check is ran on whether the player ran into a trigger -> If the player did, we see if he was already in it, just ran into, left, etc. -> Trigger stuff ran.
At the moment what I have implemented for the projectile code is the BuildPolyList, the mConvex, and all the polyList stuff at the top of the findContact function. My problem is i'm not sure why I need some of this (hence the questions above) so i can't come to making it all work.
09/23/2005 (12:25 pm)
*Edit*Still having trouble with this... can anyone explain the process which occurs from the player moving to the trigger entry?
I understand that every tick the findContact function is ran for the player, but what I don't get is how the polyList is used and where the variables are coming from. I'm unsure of the usage of the buildPolyList for the player, and whether the polyList information at the beginning of the findContact function is the "magic" that makes it all work.
Is the polyList for the trigger or the projectile?
As far as I understand it:
Player Moves -> findContact ran -> Somehow a check is ran on whether the player ran into a trigger -> If the player did, we see if he was already in it, just ran into, left, etc. -> Trigger stuff ran.
At the moment what I have implemented for the projectile code is the BuildPolyList, the mConvex, and all the polyList stuff at the top of the findContact function. My problem is i'm not sure why I need some of this (hence the questions above) so i can't come to making it all work.
#4
09/25/2005 (8:58 am)
Thanks to PaulDana and much thanks to matt_f I managed to figure out what I needed and solve the issue. I'll update this post when I get some time with the solution.
Associate Paul Dana
2. You do not HAVE to have a polylist ...but if you don't then you wont be able to simply clone the code from Player. Player checks for collisions against triggers using a convex and the working set. This is code which makes use of the binning system to find objects that this object (the player) intersects with. If you do not have the poly list you cannot use this method...you will have to find some other way of finding which triggers contain this projectiles position.
3. You want to do it on the server in processTick() not in onCollision(). Players do it in findContact() called from updateMove() called from updatePos() called from processTick.
4. trigger->potentialEnterObject(obj); is code to say ok this object is INSIDE a trigger right now. In Player this is determined using the poly lists. The reason it says "potential enter" is that you may already BE inside this trigger and if so the trigger will not fire another "enter" event.
Good luck