Game Development Community

StaticShape / TSStatic / Collision Questions

by Jake Callery · in Torque Game Engine · 03/29/2007 (7:55 pm) · 3 replies

Hi There,

First let me apologize if the following questions are a little too "noobish" for this forum, but I've run out of places to search for answers :)

Firstly, what is the difference between StaticShapes and TSStatic shapes?

Second, I have been trying to find a way to make an object that I can stand on / walk around on and at the same time have the object notify me of a collision, much like an "item" object can do.

So for instance I would like to make a crate, and when the player jumps down on top of it I would like
the player to "Stand" on it and have the object do something such as change color or whatever.

Right now with TSStatic shapes, I can stand on those and walk around, but there is no "onCollision" callback for those it seems. So my guess would be to somehow modify TSStatic objects to have an onCollision callback.

As a side note, I would like to use a fair number of these types of objects in the mission. I'm not sure what kind of impact that information will have on how to make this happen.

I have looked at and implemented the Item Collision resource, however I have two issues with it.
1) I fall through the terrain, but at the moment, thats not that important.
2) I do collide with items, however if I am on top of it (standing on it) I can no longer move the player around. I'm assuming its because I am constantly colliding with it.

Now I have tried making TSStatic objects and putting triggers on top of those, but that is a great deal of work per object. So its not really the way I want to manage lots of these objects.

So if someone could point me in the right direction here I would very much appreciate it.

Thanks ever so much for the help!

Jake

#1
03/30/2007 (4:03 am)
Hi Jake,

As I understand it, the difference between TSStatic and StaticShape is that TSStatic objects have no scripting capabilities - they are simply models you can place in game and collide with.

StaticShape objects on the other hand can be scripted, so you can do all sorts with them. As for the crate example you mentioned, if you add your crate to the level as a StaticShape, you'll have the ability to collide with it and also have the benefits of the onCollison function (and many others). Your script file would look something like this:

datablock StaticShapeData(Crate)
{
    shapeFile="your path to model";
    category="Test objects";
};

function Crate::onCollision(%this,%obj,%col)
{
    //put your code here
}

Once you got all that loaded in your game, add your crate to the level - in the editor, you'll find it under Shapes->Test objects->Crate.

--Amr
#2
03/30/2007 (6:32 am)
Hey Jake, sorry to have made things so complicated before (bad tendency of mine). I should have just ran some tests first, and just provided you with what worked.

Amr has it right. I tested a mission with stock TGE 1.5, using a boulder:

In example\starter.fps\data\missions\sgLightingPackDemo.mis, I added this:
new StaticShape(testBoulder) {
      canSaveDynamicFields = "1";
      position = "-45.704 192.744 227.121";
      rotation = "1 0 0 0";
      scale = "1 1 1";
      dataBlock = "BoulderStaticShape";
      receiveSunLight = "1";
      receiveLMLighting = "1";
      useAdaptiveSelfIllumination = "0";
      useCustomAmbientLighting = "0";
      customAmbientSelfIllumination = "0";
      customAmbientLighting = "0 0 0 1";
   };


In example\starter.fps\server\games.cs, I added this in the function onServerCreated():
exec("./crossbow.cs");
exec("./environment.cs");
[b]exec("./boulder.cs");[/b]   // NEW CODE HERE

In example\starter.fps\server\games.cs, I created boulder.cs, which has the following:
datablock StaticShapeData(BoulderStaticShape)
{
   category = "Rocks";
   className = "Boulder";
   shapeFile = "~/data/shapes/rocks/boulder.dts";
};

function BoulderStaticShape::onCollision(%this,%obj,%col)
{
   echo("Collision with BoulderStaticShape");
}

My player collided with the boulder and was able to stand on it, without getting stuck. Every time I touched it, I got this message:

Collision with BoulderStaticShape
#3
03/30/2007 (7:15 am)
I could have sworn I tried that before starting these posts.

I must have messed it up somewhere along the line. I will try this again as soon as I get home from work.

I think I was getting TSStatic and StaticShape confused with each other.

Thanks very much for everyone's help! Sorry for the "new guy" questions.