Game Development Community

Mounted objects and collision

by Amr Bekhit · in Torque Game Engine · 09/15/2006 (1:29 pm) · 8 replies

Hi all,

I've been trying to implement a sword by mounting the shape to a player hand then checking for collision using the onCollision callback. Unfortunately, the callback isn't called. After a search on GG I get the impression that collision is disabled when an object is mounted. I've had a look at the Realm Wars code (they have melee weapons), but I'm having trouble understanding what is going on. I think that it would be a lot simpler if I could enable collsion for mounted objects. I've done lots of searces in the TGE source code to see if there's a simple flag or function call that can be modified so that collision isn't disabled, but I was unable to find any. Anyone know where I can enable this?

--Amr

#1
09/15/2006 (1:33 pm)
Collision for mount objects work just fine, however, you did not specify *what* you are mounting so everyone will have to guess what the problem is. Different classes behave in different ways.

Is it a shapeBaseImage, perhaps? Images do not even tick, and thus cannot react to collisions. You have to use something else, like staticShape.
#2
09/15/2006 (1:42 pm)
Sorry about that. The sword is a StaticShape which I've mounted on to the player when the player is added to the game using mountObject. Here is the code for the sword:

//sword.cs

datablock StaticShapeData(SwordData)
{
   shapeFile="./sword.dts";
   isInvincible=true;
   damage=40;
};

function SwordData::onCollision(%this, %obj, %col, %vec, %speed)
{
   echo("Sword collided with something");
   //Here is where the sword does damage
   //first we need to check if the sword is being slashed or not
   if (Sword.attackStatus==false)
      return;  //The sword isn't slashing so  just quit
   
   //Here the sword is slashing, so we need to apply damage
   if (%col.getType() & $TypeMasks::ShapeBaseObjectType) //Is this object a shape?
   {
      //it is, so we need to apply damage to it
      %col.damage(%obj,%vec,%this.damage,"Sword Slash");
      //Then apply an impulse to the object we just hit
      %colPos=getWords(%col.getTransform(),0,2);   //Get the position of the slahsed object
      
      %playerID=%obj.getObjectMount();             //Get the position of our player
      %playerPos=getWords(%playerID.getTransform(),0,2);
      
      %impulseVector=VectorSub(%colPos,%playerPos);
      %impulseVector=VectorNormalize(%impulseVector)*10;
      %col.applyImpulse(%col.getTransform,%impulseVector);
   }
}

--Amr
#3
09/15/2006 (1:44 pm)
Not sure mounted objects calculate collisions other than raycasts against their collision box.
Perhaps someone else knows for sure, good luck.
#4
09/15/2006 (2:22 pm)
Check out the skeleton pack, it has sword. Outstand job was done with it. Also the skeleton can shoot gun, throw fireball or chop you with the sword. To me it will worth the money instead try to figure everything out on my own.
#5
09/15/2006 (2:52 pm)
Again we arrive at this topic.
A topic i don't like.

www.garagegames.com/mg/forums/result.thread.php?qt=31697
There's others like that but that's the last one i remember commenting on

Anywhoo.... collision isn't gonna work like you think.
First off, only players, rigidshape, vehicles, and items actively check for collisions.

Moutning an object with a collision mesh to the player and then animating the player, will not produce any collisions.

Collisions are disabled when you mount an object to a player, enabling this collision will cause the player to constantly collide with that object, Even still swinging that object around will NOT detect a hit. that seems to be due in part to the code related to it being mounted.


The way the realm wars melee works is thru a raycast thru the sword object. That melee resource and a new one called Simple Melee is available.
#6
09/15/2006 (3:18 pm)
Quote:
Collisions are disabled when you mount an object to a player, enabling this collision will cause the player to constantly collide with that object, Even still swinging that object around will NOT detect a hit. that seems to be due in part to the code related to it being mounted.

This is not true. I really dont know why it wont work for you, but if you mount a staticShape to a player and cast a ray to the object, it will hit. If you also try to go into the object, it will collide with your control object, whatever it is.

Anyhow, most sword solutions that I've seen are castRay based. I suggest the OP to try that.
#7
09/15/2006 (3:20 pm)
Thanks for the info guys - I'll look into this ray casting implementation of swords and melee weapons.

--Amr
#8
09/16/2006 (10:26 am)
Stefan,
Go create a walking robot with mount points on the leg joints. Now mount a static shape with a collision box to each mount point. Then make your main object collision box defined in the player datablock too small. You will constantly collide with the static shapes and will not be able to move. Now the two players cannot get close enough to hit each other because of the player collision box. You will also register collisions from other objects to the static shapes. Hence you can walk up the legs. Maybe we are saying the same thing a different way.