Game Development Community

Torque Scripts - get 'em while they're hot

by Dev Jana · in General Discussion · 02/02/2007 (7:59 am) · 1 replies

I've uploaded many of the basic scripts to my site that I use to help beginning Torque users (like my students) deal with the engine. Feel free to get and use them as you see fit, but give credit where it is due. Here's a list of the scripts and their functions/methods:

basics.cs:

getObjectTerrainZ()
returns the Z height of the terrain at an objects position
EX: $height = OBJECT.getObjectTerrainZ()

impulse( %velocity )
applies an impulse to an object with the given velocity
EX: OBJECT.impulse( "-9 27 81")

getDistanceFrom( %otherObject )
returns the 3D distance from one object to another
EX: OBJECT.getDistanceFrom( OTHEROBJECT );

getVariedPosition( %xVariance, %yvariance )
returns a position that randomized to be within the given X and Y variances and at the terrain height.
EX: OBJECT.getVariedPosition( 12, 15 )
Will return a position within 12 of the X position of the object and within 15 of the Y position of the object on the terrain.

shaper.cs:

Make sure that any dts shapes that you want to use are in folders that have the same name as the shape in the "data/shapes" folder in the project.
Ex: "thing.dts" should be in the "thing" folder in "data/shapes" - data/shapes/thing/thing.dts.
Now, once you are in-game, run the following line in the console:
addItem( "thing" )
This will create an itemData datablock for the shape as well as a function "newThing( %position)" which creates an instance of the item at that position.
Try the following line in the console:
newThing( "0 0 0" );
This will create a "thing" item at the position "0 0 0".
The script for the shape is now saved in the "server" folder of your project. It will be name "thing.cs". You can edit the file as you need for use in game later on.

grower.cs:

Adds a method "OBJECT.grow()" that uniformly grows a shapeBase object to a scale of "1 1 1".
OBJECT.grow()
Change the parameters in grower.cs to fit your needs.

rayCheck.cs:

Returns the handle of an object of a given type if the object can be seen from the ray being cast from the player's current eye vector and is within the given distance.
EX: rayCheck( 100, "item" );
Will cast a ray from the player's current eye vector up to a distance of 100 units. If the ray collides with an item, the handle for that item will be returned.

I've also posted a few template scripts that I use. U may use my scripts in any projects you like. Just list my name and/or website in the credits.

NJoy
~Dev Jana
www.devjana.com