Mow a Meadow with Torque 3D

Hello Friends – here a little Tutorial on how to change the groundcover on the position of the player – so you can make an mow – effect – have fun (thanks to LukasPJ) 😉

First you have to Download the whole Torque 3D Sourcecodes (

Then get the Sourcecodes in Visual Studio -> look here:

Then we need to know, that we want to change the Groundcover on a specific position in the Game. Therefore we need to change the Terraintexture on this position and can then layer the Groundcover on it.

So we now make the file (we will name it) „mow.cs“ in the „scripts/server/“ folder of your game directory.

And we put the following in this file:

function mow(%this) {


//sets the position all 50 milliseconds
$eventID = schedule(1000, 0, mow);


function stop_mow(%this) {

echo("mow off");


function start_mow(%this) {


echo("mow on");



Here you can play around with the index of the ground materials – its the number here:


and with the interval to change the mow speed ground materials:

$eventID = schedule(1000, 0, mow);

At the next step we need to add this script into the „scriptExec.cs“-File in the „scripts/server/” Folder of your Game Directory. Add this line somewhere in the file:


Now open the File „terrainEditor.cpp“ in Visual Studio and add this code somewhere in the file:

DefineEngineFunction(paintTerrainUnderPlayer, void, (U32 mat), (1), "")
    // Create a new instance of the TerrainEditor so we can use its functionality.
    TerrainEditor *mTerrainEditor = new TerrainEditor();
    // Get the connection to the player.
    GameConnection* connection = GameConnection::getConnectionToServer();
    // Fetch the player.
    Player* playerObject = dynamic_cast< Player* >(connection->getControlObject());
    // Get the player's position.
    Point3F pos = playerObject->getPosition();
    // Grab a point above the player.
    pos.z + 5;
    // Fetch the terrain with a ray-trace. There are probably more efficient ways to get this.
    TerrainBlock *terrain;
    RayInfo r;
    bool hit = gClientContainer.castRay(pos, Point3F(pos.x, pos.y, pos.z - 1000), TerrainObjectType, &r);
    if (hit) {
        terrain = dynamic_cast<TerrainBlock*>(r.object);
    // Initialize the GridInfo and GridPoint that our player's position maps to.
    GridInfo gi;
    GridPoint gp;
    // Specify the terrain this GridPoint belongs to.
    gp.terrainBlock = terrain;
    // Map the player position to a point on the grid.
    gp.gridPos = gp.terrainBlock->getGridPos(pos);
    // Get the Terrain information at that point on the grid (such as texture, height etc.)
    mTerrainEditor->getGridInfo(gp, gi);
    // Map the material as dirty.
    gi.mMaterialChanged = true;
    // Change the material (to a layer which can be between 0 and 31).
    gi.mMaterial = mat;
    // Update the grid.
    mTerrainEditor->setGridInfo(gi, true);
    // Repaint the terrain.
    terrain->updateGridMaterials(gp.gridPos, gp.gridPos);

And add the header files in “terrainEditor.cpp”:

#include "T3D/player.h"
#include "T3D/gameBase/gameConnection.h"

On the end of the other “.h” files at the top of the “terrainEditor.cpp” file.

Congratulations – now just compile and you have a working function to change the “TerrainTexture” at the Position from the Player!

Now let’s start your game after compiling it!

Okay – we want to change the groundcover on the position of the player – so we just need to layer some terrain material on the type of your groundcover.

Further use your desired terrain texture, which is set as meadow – so only there the grass, would be.

And use “0” in our case as a TerrainTexture – this would be replaced and so there is a “mowing effect” because you layered it on another Texture 😉

Okay now you are ready!!!

Just open the console in the Terrain Painter Editor and type “start_mow” now just walk through your Groundcover and have look at this cool thing – if you want to stop “mowing” just use “stop_mow” 8)

So now this Tutorial is understand as an RFC Document – so you are welcome to send me your Comments.

Best Regards!