Game Development Community

dev|Pro Game Development Curriculum

(Dynamic) StaticShape T3D Example

by Steve Acaster · 08/08/2010 (2:36 am) · 8 comments

Make a new *.cs file and call it staticshape.cs, and place it anywhere you like - though I'd suggest art/datablocks. Remember to exec the file in art/datablocks/datablockExec.cs.

As an example we'll use a stock Torque rock (art/shapes/rocks/rock1.dts) and we're going to make it vanish when a player touches it. This new staticshape object we'll call DynamicRock ... because staticshapes are really dynamicshapes ...

In your new staticshape.cs put this.
datablock StaticShapeData( dynamicRockData )
{	
   category = "StaticShape";//adds a folder category to the world editor scripted section if there isn't one already
   shapeFile = "art/shapes/rocks/rock1.dts";
};

function dynamicRockData::onCollision(%this,%obj,%col)
{
	if(isObject(%obj))//don't do anything if we don't exist :P
		{
			if (%col.getClassName() $= "Player")
			{ 
				%obj.delete();
				echo("DynamicRock has been touched by a player - piff paff poof - it's gone!");
			}
			else
			{
				//do nothing, cos it's not a player that has collided
			}
		}
}

Boot up T3D and open up the world editor in a level. See the new StaticShape folder under World Editor->Library->Scripted. Open up this folder and you should the DynamicRock object. Place one in the level, on the ground where the player can get at it. Quit the editors and go back to the game - and now run the player into the rock and watch it vanish on contact - magic!

#1
08/08/2010 (7:10 am)
You're in the wrong job Steve, you should be a magician on the royal variety show. :) - nice work!
#2
08/08/2010 (10:56 am)
I was going to make a Tommy Cooper reference ... but obviously no-one but Brits over 30 would get it ... :P
#3
08/08/2010 (11:19 am)
maybe a muppet reference instead - wagga wagga wagga -

edit: for the reference, I'm not calling you a muppet or anyone else for that matter, and no muppet or stuffed animal was hurt in writing this. Everyone knows the muppets :)
#4
08/11/2010 (3:28 am)
@Steve
You are an excellent Tutor - I would say
I am new in Torque 3D and always scare to see/do scripting part of it but you made this topic so easy to learn...
thanks should we wait for such more topics from you(in this simple way of demo) - something to control Players movement with mouse (Like Commandos BEL) ?
#5
08/11/2010 (6:08 am)
Steve are you going to write a dummies guide to T3D for the documentation project?
#6
08/11/2010 (10:35 am)
@Sailesh
Try to follow the RTS tutorial in the T3D Docs (under sripting)(though I think someone said that they had problems with it a while ago). I've not tried it.

@Jesse
lol, no, I was answering a post asking about colliding callbacks and was saying to look in staticshape.cs for an example ... when I realised that there wasn't a staticshape.cs to give an example.
#7
08/16/2010 (1:00 pm)
Quote:lol, no, I was answering a post asking about colliding callbacks and was saying to look in staticshape.cs for an example ... when I realised that there wasn't a staticshape.cs to give an example

Just like Tommy, the performance of the trick went wrong, but ends unexpectedly (is this English???) right.
#8
02/05/2011 (11:26 am)
Tnx a lot for this, it help me A LOT =)