Game Development Community

A Question about mounting and damage

by Bryce "Cogburn" Weiner · in Torque Game Engine · 06/19/2005 (12:15 am) · 11 replies

If I have an object mounted to a player or vehicle and a projectile hits that mounted object can that object take damage or is damage automatically passed to the object it is mounted to? If the damage is passed, can this be interrupted in some way so the object that is struck takes the damage rather than that which it is mounted to?

#1
06/19/2005 (12:19 am)
Nope, collision is turned off for mounted objects.... you can turn them back on, but then you've got problems with the player constantly running into the object that's colliding against him, so then you've gotta find where the collision code is gettin' tested, and make sure that it's not colliding against any objects that are mounted to it.
#2
06/19/2005 (12:30 am)
I dont see anything in shapebase.cc or projectile.cc that would indicate that this is happening... Do you know where this is occurring?

EDIT: I didn't look hard enough.

//----------------------------------------------------------------------------
void ShapeBase::mountObject(ShapeBase* obj,U32 node)
{
//   if (obj->mMount.object == this)
//      return;
   if (obj->mMount.object)
      obj->unmount();

   // Since the object is mounting to us, nothing should be colliding with it for a while
   obj->mConvexList->nukeList();

   obj->mMount.object = this;
   obj->mMount.node = (node >= 0 && node < ShapeBaseData::NumMountPoints)? node: 0;
   obj->mMount.link = mMount.list;
   mMount.list = obj;
   if (obj != getControllingObject())
      obj->processAfter(this);
   obj->deleteNotify(this);
   obj->setMaskBits(MountedMask);
   obj->onMount(this,node);
}

Thanks for pointing me in the right direction. I don't think it will take much to get this working. The problem then becomes what is the best way to avoid all those collision checks without adding much overhead.
#3
06/19/2005 (1:00 am)
It's too late for some decent testing but I'm going to leave it for after Father's Day brunch.... But here's what looks like might work...

void ShapeBase::mountObject(ShapeBase* obj,U32 node)
{
//   if (obj->mMount.object == this)
//      return;
   if (obj->mMount.object)
      obj->unmount();

   // Since the object is mounting to us, nothing should be colliding with it for a while
   // BW061905
   //obj->mConvexList->nukeList();  // Commented out this line to leave the convexlist

.... and then change ....

void ShapeBase::queueCollision(ShapeBase* obj, const VectorF& vec)
{
   // Add object to list of collisions.
   SimTime time = Sim::getCurrentTime();
   S32 num = obj->getId();
   bool noCollide = false;
   // BW061905
   if (obj->isMounted()) {	
      noCollide = (obj->getObjectMount()->getId() == this->getId());
   }
   if (this->isMounted()) {
      noCollide = (this->getObjectMount()->getId() == obj->getId());
   }
   if (!noCollide){
   // BW061905
      CollisionTimeout** adr = &mTimeoutList;
      CollisionTimeout* ptr = mTimeoutList;
      while (ptr) {
         if (ptr->objectNumber == num) {
            if (ptr->expireTime < time) {

...

   }
}

Should be self-explanitory, but for posterity.... I leave the ConvexList in tact when the object is mounted. Then when the collisions are queuing we ask 2 sets of questions A) Is the object that I am colliding with mounted, and if so is it mounted to me OR B) Am I mounted and is the object I am colliding with my parent? If in either case the answer is yes, you simply drop out of the collision queue and voila! (I hope)
#4
06/19/2005 (1:50 pm)
LOL this solution is.... not good.

After about 2 minutes the game hard locks, and not even the 3 finger salute can bring it back.

I think that the repeated calls to queueCollision finally made it throw in the towel.

I think the parent-child checks are in the wrong place. They belong in shapeCollision.cc. I need to cut off the collision checks BEFORE it reaches the queue.

The saga continues....
#5
06/20/2005 (2:35 pm)
Turns out it wasn't TGE, but a fault in my video card RAM. A quick trip to Best Buy solved that.

Good news is that it forced me to look at the code again... shapeCollision.cc is still the best answer.

Now that I've got my rig back in order I'll be recoding and testing this a little more tonight.
#6
06/30/2005 (10:51 am)
Any word on if this works as it should? Its not working for me. The oncollsion funciton no longer calls, however, my player is still hitting the mounted object.
#7
06/30/2005 (2:35 pm)
To be honest, the further I got into this the more I realized that I should attack the problem differently.

For external mounted objects (ie: destroyable mounted weapons) I switched to a hitbox scheme. For players mounted on or in vehicles... well... that isnt an issue for me so I kinda passed on it all together.

If you are looking for a solution that deals with players, I'd suggest using a castRay to see if you actually COULD have hit the player were it not mounted. This is a lot of calculation per projectile, since you would have to reference the vehicle you hit, then iterate through all the passengers in the vehicle to see if your castRay result would intersect with one of their positions. Then there is always "did I shoot them through the window", which that solution would not cover. I guess you could use the same method, and then check to see if you hit a transparent texture on the vehicle (a window), and THEN iterate through the passengers.

Sorry, but in the end it was just simpler to rethink how I wanted to achieve my goal.
#8
06/30/2005 (2:52 pm)
I see. i'm just trying to find the simplest way to setup melee. seemed like just monitoring the oncollision for a mounted shape would do it. the hitbox tutorial is so complicated, dunno if i wanna try messing with that one again.
#9
07/02/2005 (9:14 am)
Check this resource for hitboxes if you haven't already. It's definately the easiest solution.

And just so we are on the same page, is this the melee tutorial you are using? I know that there are several bouncing around, but that one is the "cleanest" implementation I've seen.

Melee is NOT a drop-in kind of change if you want to do it accurately. What I was attempting to do may not have helped you at all from your description. The server-side melee tutorial is complex, but still the best way to go because A) it works and B) if you run into trouble there are lots of people that have gone before you.... e.g. you will have places you can turn to for advice should you run into trouble.
#10
07/02/2005 (11:29 am)
I was about to try to implement that hitbox resource... now i'm pretty stuck on the other melee turtorial, as you can see on it, i've got the last few posts about the problems i encountered, and there's been no responses so... i'm stuck with that an no one has helped. I'm not interested in the entire melee system. i only need to have some way for me to know when i've hit something with another object. easiest i thought would simply to monitor the collsion events of a mounted object. but that's a no go