Game Development Community

StaticShape::onCollision not called

by Michael Perry · in Torque Game Engine · 11/13/2006 (10:28 am) · 15 replies

Hey all. I've been hammering away at this problem for a while. I have two StaticShape objects. I need one object to mount to the other when they collide.

I came across this old thread, but a solution was never posted:StaticShape Collision

I have the same problem, and here is what I have in script:

datablock StaticShapeData(BriefCase)
{
   category = "Containers";
   className = "BriefCase";
   shapeFile = "~/data/shapes/briefcase/briefcase.dts";
};

datablock StaticShapeData(Book)
{
   category = "Objects";
   className = "Book";
   shapeFile = "~/data/shapes/book/bookdts";
};

function BriefCase::onCollision(%this,%obj,%col)
{
   echo("BriefCase::onCollision occured");
   if (%col.getName() $= "Book")
   {
      echo("Book collided with BriefCase");
      case.mountObject(book, 0);
   }
}

The first echo() in BriefCase::onCollision never even occurs. So, even after debugging, the onCollision routine is never called. Any suggestions?

#1
11/13/2006 (10:43 am)
I don't think you're supposed to use the same label for your name and your classname. You can definitely create methods for each, but try using separate names for them rather than the same name. you may be creating some kind of ambiguity there.
#2
11/13/2006 (10:50 am)
@Sean - Thanks for the quick reply and suggestion.

Ok, I tried changing the classname, but nothing changed. BriefCase::onCollision() still didn't get called.

datablock StaticShapeData(BriefCase)
{
   category = "Containers";
   className = "Case";
   shapeFile = "~/data/shapes/briefcase/briefcase.dts";
};

datablock StaticShapeData(EnglishBook)
{
   category = "Objects";
   className = "Book";
   shapeFile = "~/data/shapes/book/bookdts";
};

function BriefCase::onCollision(%this,%obj,%col)
{
   echo("BriefCase::onCollision occured");
   if (%col.getName() $= "EBook")
   {
      echo("Book collided with BriefCase");
      case.mountObject(book, 0);
   }
}

*EDIT - What I have now*
#3
11/13/2006 (1:46 pm)
Perry, just for verification post the code where youre instantiating the objects which use these datablocks. There could be some problem there. This code looks OK to me.
#4
11/13/2006 (1:52 pm)
Gladly Sean:

new StaticShape(case) {
      position = "110.656 -219.889 125.094";
      rotation = "1 0 0 0";
      scale = "1 1 1";
      nameTag = "BriefCase";
      dataBlock = "BriefCase";
   };
new StaticShape(EBook) {
      position = "110.55 -219.794 125.15";
      rotation = "0 0 1 89.9812";
      scale = "1 1 1";
      nameTag = "EnglishBook";
      dataBlock = "EnglishBook";
};
#5
11/13/2006 (3:02 pm)
Michael, try removing the double quotes around the dataBlock values. it's a stretch, but the code may be considering those as regular strings rather than datablock labels.

other than that, can't say i see much of a problem with your code.
#6
11/13/2006 (5:22 pm)
datablock StaticShapeData(BriefCase)
{
   category = "Containers";
   //className = "Case"; // No class definition needed
   shapeFile = "~/data/shapes/briefcase/briefcase.dts";
};

datablock StaticShapeData(EnglishBook)
{
   category = "Objects";
   //className = "Book"; // No class definition needed
   shapeFile = "~/data/shapes/book/book.dts";
   image = EBookImage;
};

datablock ShapeBaseImageData(EBookImage)
{
   shapeFile = "~/data/shapes/book/book.dts";
   item = EnglishBook;
   mountPoint = 0;
};

function BriefCase::onCollision(%this,%obj,%col)
{
   echo("BriefCase::onCollision occured");
   if  ( %col.getDataBlock().getName() $= EnglishBook )
   {
      echo("Book collided with BriefCase");
      //case.mountObject(book, 0); // Cannot mount a staticshape o a statick shape you need Imagedata
      %obj.mountObject( %col.getDataBlock().image, 0 );
   }
}

If that does not work then the engine does not register staticshape to staticshape collisions. You would have to modify the source code.
#7
11/13/2006 (5:29 pm)
Zod, you make things very clear, Thank You. You understand TScript very, very well[especially if that's your commenting all over Tribes II scripts, ;)]. Please never stop!
#8
11/13/2006 (5:41 pm)
@Rex- Thanks for contributing =)

@Zod - I'm going to give this a shot tomorrow. I was trying to stick to StaticShape to StaticShape collision and mounting, but with the timeline I'm on, I just want something that works. I'll post my results tomorrow. I already have a premonition, but since it involves engine code, I won't say anything further. Wish me luck.
#9
11/15/2006 (4:30 am)
StaticShapes by nature do not move so they are not checked for collisions. Only objects that move are checked for collisions when they do move, so a player walking into a staticshape will collide. A player that stands still and gets hit by a staticshape will not collide, and two static shapes that hit eachother will not collide either.
#10
11/15/2006 (5:51 am)
You beat me to it Stefan!

Yup, that's why I changed my objects from StaticShapes to Items. . .but oh, wait! Items don't collide with each other, and they keep rotating!!! So, enable collision with other items, disable rotation, and I'm finally getting some results. There seems to be a problem with bounding boxes though, but I found a nice resource that I'm trying to implement to create a simpler bounding volume. Thanks for the help so far everyone!
#11
11/15/2006 (5:15 pm)
If you are using TGE 1.4.2 or 1.5 you would be best off using RigidShapes. They DO collide with each other.
#12
11/15/2006 (5:33 pm)
I have the working demo that I wanted. I am using items, with disabled rotation and modified gravity settings. Collisions and mounting are working beautifully. Just gotta finish the demo. Thanks again everyone.
#13
11/16/2006 (4:12 pm)
Rex, thank you. Yes the ZOD all over the scripts is I. I try to help when I can.

I posted a Dev snapshot that hopefully helps alot of people get something up and running faster then the default starter kit that comes with TGE. Just waiting on the approval. Worst case I'll post it in a blog.
#14
11/17/2006 (7:50 am)
That sounds like a really great Resource, Zod, I think I remember reading it.... Anything you have come up with should be of a very high quality! I cannot count how many times in those scripts I see your comments. I must be getting sick; I am finding it more 'enjoyable' reading code than playing the game....!
#15
11/17/2006 (8:19 am)
I would not recommend using the heavy RigidShape class unless you need the functionallity it offers over other alternatives.