Game Development Community

Requesting Basic Script Examples...

by Dagem Mammo · in Torque 3D Professional · 09/01/2009 (2:17 am) · 31 replies

I have been reading through the Torque Book (Game Programming Guide to Torque).. but it seems that it is a bit outdated.


I tried implementing some scripts.. so far I can get a basic static object to load and drop from the sky.

The problem is that when I try to follow some of the examples of the book.. many of the object names have changed.. like the new MissionGroup.. I have not been able to find the replacement for the "BaseItem" class I wanted to extend like they do on the book.



So I'm simply requesting some sample scripts with basic meshes/collision data.

I want to learn more about the way torque does "animations"... so I can move a model across a plane.. etc etc.. is it just based on some transformation + loop? If so what is the best way to do this.. seeing as how something like "sleep" is not really what I want.


Basically I want to learn very basic things like being able to move an object across the screen (eventually activate a walking animation as the obj moves), collision detecting that causes an action (so picking up an item or talking to an Avatar). I'm assuming that I need to extend on the Player or Vehicle class for many of these examples? Once I am able to do these basic things I can move on to implementing more interesting things like state machines and other game AI.... which I have done in other simpler systems.. but I just can't find many useful examples for Torque 3D.


Thanks






Page «Previous 1 2
#1
09/01/2009 (6:10 am)
play around in the resource section.

Try the Yellow torque book it helped me a lot, they walk you through creating a game and doing everything you are talking about, by the end you should know all about using datablocks, GUI's and partials, even event handling.

If that is the book you are talking about, just look in the demo files you will find similar setups just rename what you need.
#2
09/01/2009 (9:21 am)
What's the name of the yellow book??
#3
09/01/2009 (11:14 am)
The Game Programmer's Guide to torque from GGpress
although even it is based on TGE not T3D
#4
09/02/2009 (4:36 am)
Yeah, that's the book I mentioned in my first post....

Anyway, I would love to look at the resources.. but how do I sort them to only include TGEA and TG3D?


Or could someone PLEASE just give me an example on how to
1) move an object along a path (it can be as simple as a straight line)
2) How to activate an models animation?
#5
09/02/2009 (9:03 am)
I know what you mean and I feel what you say. I agree its rough.

First things first. All script code is pretty much the same. Just like programming a for loop is a for loop. a Do - while is do - while. a IF statement is an IF statement.

In the engine the AI player has a couple of methods already in place to determine points.
A: already at said point
B: not at said point
C: am I suppose to go to said point.
D: am I suppose to look at the point I am going too.
Or at least it did in TGEA. I really haven't tested it in T3D since I've been more worried about it's multiplayer behaviors since most of my creations will be multiplayer.

ok now that I got that out of the way:
Question 1).
Step 1) Make an object
Step 2) Load the object in game
Step 3) make the object a known engine time that behaves according to the style that you are looking for
Step 4) Make the object reference engine call backs via script
I will assume you have already done steps 1 - 3 and are looking only for the script call backs.
First If I call the class name function all AIplayers unless otherwise specified will use this callback.
new aiplayer("Harry")
{
   datablock = playerdata;
}

AIplayer::ONLOAD(%THIS)
{
   //Start AIPlayer thinking at a scheduled time(If the Ai thinks we can make it do things later)
   %this.think();
}

AIPLAYER::Think(%this)
{
   if(!%this.waypoint) //if the player already has a waypoint which is a 3D position XYZ go there
   {
       %this.setDestination(%this.waypoint);
       %this.moveToDestination();
   }
   
   %this.schedule(500, 'think'); //every 1/2 a second think again
}
This is just example code you would of course have to make your own code and what it will do.

As for model animations. There are a couple of ways I can think of. First you need to understand that there are some default animations already built into the engine. If you have the artist name the animation according to the sequence name that the engine recognizes then it will act like a normal player's animations would. IE walk forward would make it walk forward etc. Sidestep would make it sidestep. Fall would play the thread for falling. etc.
I mentioned threads because an Player object has the ability to play 4 animation threads at a time. I'm not saying that it would look pretty I'm just saying thats what's coded in the engine. You can do a lot of stuff with just 4 threads(0 - 3). 0 normally is your i'm walking around thread. 1 could be your my head is looking at you and my gun is facing the other guy. so theres 3 threads.
If all you wanted was a simple console command
then Hit ~
and type
%object.playThread(0, 'run'); //where %object is the GAME (object number) and 0 = the 0 - 3 thread you want it to play on and 'run' is the unique name specified for the animation sequence.
Do not be confused. Your character had 4 Animation threads that can be used to play a number of Animation Sequences. I just used run for this example.

I'm sorry if this didn't make sense i'm a little tired. But I hope it helps you.
#6
09/02/2009 (12:26 pm)
Thanks, I think it mostly made sense except I believe I'm doing something wrong.. perhaps not extending the right class? (So I'm getting an error telling me that the method setDestination is not defined, additionally, I'm not sure what format the waypoint should be passed in as, perhaps "x, y z" ie "30.0 0.0 50.0").


Here is the code I have so far to load a model into the world (note I use BaseItem as the base class).


datablock ItemData(TestShape: BaseItem )
// ----------------------------------------------------
// Definition of the shape object
// ----------------------------------------------------
{
// Basic Item properties
shapeFile = "~/../art/shapes/items/bear.DAE";

};


function InsertTestShape(%x_var)
{
// An example function which creates a new TestShape object
%shape = new Item() {
datablock = TestShape;
rotation = "0 0 1 0"; // initialize the values
// to something meaningful
static = false;
rotate = false;


};



$last = " 0 20 0 0 1 0";
$string = %x_var SPC $last;
//TODO: Note this is new .. or maybe the MissionGroup obj is now the new standard name
MissionGroup.add(%shape);

// Player setup
//%shape.setTransform("0 0 20 0 0 1 0");
echo($string);
%shape.setTransform($string );

echo("Inserting Shape " @ %shape);
//return %shape;

%shape.setDestination("0 20 0 0 20 40 30");
%shape.moveToDestination();

}

InsertTestShape("0");

#7
09/02/2009 (12:33 pm)
Also, if you don't mind me asking.. where did you learn this stuff? I don't mind buying a Genre kit if it means I can have access to such example code .. but I 'm afraid it might be too much code that I don't need and it will not be as helpful as I might suspect it can be.
#8
09/02/2009 (12:46 pm)
read tyhe code that comwes in the example demo's they do this everywhere
#9
09/03/2009 (11:13 pm)
I must be honest.. and say I looked through the FPS sample code (under game/scrips/server) but I was unable to find this example. I found the AIplayer class.. tried to trace the callbacks from the initialization to see where the AIPlayer is ever spawned but I'm not able to figure it out. The other thing is that ... in the short time that I played the FPS, I never did see any AI...... so my question remains, how do I initialize a simple AI / object that moves from point A to point B (it can be as simple as a straight line).

Thanks
#10
09/03/2009 (11:30 pm)
look at my resource for AI
#11
09/04/2009 (12:40 am)
Hopefully this will get peeps started (Yes I'm Bored).

Beta4/5

www.bitSlap.me/NPC_AI.cs

Place In Folder
game\art\datablocks


Extract Contents Of www.bitSlap.me/BaseMale.zip In Folder
game\art\shapes\players\BaseMale


Modification 1
File: game\core\scripts\server\spawn.cs

Add Line at 186
%player.GlossaryName="PlayableCharacter";


Looks like this after your done:
// If we have an object do some initial setup
      if (isObject(%player))
      {
         // Set the transform to %spawnPoint's transform
         %player.setTransform(%spawnPoint.getTransform());
         %player.GlossaryName="PlayableCharacter";
  
      }
      else

Modification 2.
File: game\art\datablocks\datablockExec.cs

Add line at end of file
exec("./NPC_AI.cs");

That should be it head to the game you will find a new Scripted Item.

www.bitSlap.me/Img1.jpg

www.bitSlap.me/Img2.jpg

Here is a video of the NPC (At the end of the video)



Here is the info of the resource used, Mucho thanks to Kevin.

www.garagegames.com/community/resources/view/17253


Read and Re-Read the resource & comments & code they should get you going.

Be warned the AI are armed and shoot to kill, my pefered choice.

Cya' Around
#12
09/04/2009 (12:44 am)
Quote:
in the short time that I played the FPS, I never did see any AI...... so my question remains, how do I initialize a simple AI / object that moves from point A to point B (it can be as simple as a straight line).
None of the levels that have shipped with the Betas have had any kind of AI enabled for them -- that's why you don't see them. What you describe is what is known as pathed AI.

The 1st thing you will want to do is find where the AIManager is initialized in gameCore.cs, look for function GameCore::startGame(), and make sure those three lines are not commented out, as well the call to delete the AIManager in function GameCore::endGame().

Quote:
For the paths to work correctly with the code that is in aiPlayer.cs you'll use the Mission Editor to place a series of numbered path markers that make up a path.

  • 1: create a new SimGroup called "Paths" -- SimGroup(Paths)
  • 2: inside this SimGroup you will place a "Path" object. Call it "Path1".
  • 3: create a series of "PathMarkers" under the Path object, still inside the SimGroup. Place these "PathMarkers" where you want them.

  • Each PathMarker will need to have it's own "seqNum" field. This is the order in which the bot will follow the nodes(markers) on the path, 1 - 2 - 3 - 4 - etc, etc so on and so forth then back to marker #1 ad infinitum. All other fields are self-explanatory or should only take a little bit of experimentation to understand what they do/mean.

  • 4: Save the mission. Reload.

  • If all steps are performed correctly you will then see a "dumb" bot following the path you just laid out.
    Copy/pasted for the 7th time here in the forums :D

    For more advanced bot behavior that is flexible, simple yet powerful, and works great check out the Improved AIGuard Resource.

    #13
    09/04/2009 (1:09 pm)
    Hi, thanks all.... OmegaDog, unfortunately I can't find that spawn.cs file.... hmm
    #14
    09/04/2009 (1:19 pm)
    What Torque3D Beta are you using?
    #15
    09/05/2009 (9:28 am)
    :) I had not updated since version 2. Thanks for that. Okay, so now I made the changes you listed, but I don't see any AI? I started a new project using the "Full Template".... so maybe the AI is spawned under water or something? How would I have the AI spawn next to my own spawn point?


    Thanks.
    #16
    09/05/2009 (9:30 am)
    Which AI system are you using

    Improved AIGuard Resource.
    or
    NPC/MOB AI
    #17
    09/05/2009 (10:55 am)
    I believe I'm using the NPC/MOB AI as posted by OmegaDog
    #18
    09/05/2009 (11:04 am)
    If you impliment the resource i have when you open Scripted Objects the NPC will spawn where you want. Also if you want some info on dynamically adding the class to the field via code i'll have something like that soo posted to resources, it's going to be part of my battle scene resources.
    #19
    09/05/2009 (11:19 am)
    go Kevin!
    #20
    09/05/2009 (11:42 am)
    It seems I might be doing something wrong... when I double click the resource.. it adds it to the world but then it immediately crashes the world editor.
    Page «Previous 1 2