Game Development Community

Simple rotation into the Torque Game Engine?

by Shane09 · in General Discussion · 02/15/2009 (9:08 am) · 18 replies

I am modeling a coin for my game. I want the coin to rotate in a full 360. Is this possible to do with TorqueScript? It's just a shape, and I was wondering if I could have Torque rotate it for me instead of having to animate it in Blender 3D. If I did do it in Blender 3D, I would include the animation in the '.blend' file and then export it to '.dts', correct? I am assuming I wouldn't have to make a '.dsq' file for just a shape which all it does is rotate. It isn't supposed to stay still at all. Is there a certain way I am supposed to include the animation in the file while exporting? Any help is appreciated. Thanks.

#1
02/15/2009 (11:31 am)
Ok, I have a UV textured cylinder and a animated cube using only a empty shape, the cylinder, and rotation using "Rot". I export it to '.dts', and only the XYZ handles that you can drag show up. I exported a un-animated (un-textured, too) cube, and it shows up just fine in Torque. I used 'Quick Export' for the cube & the cyclinder. I also tried regular export on the cylinder. Are there any Blender experts that can help me identify what is going on here?

EDIT: I also noticed my animation won't show up under sequences. Is there a resource on exporting from Blender (including UV textured & animations) to Torque? I don't need an actual Blender tutorial, I just need to know how the set up must be.

EDIT: I also tried loading it into Torque Showtool Pro and it Unexpectedly Crashed.

I have no clue what is going on :(

Should I redo the mesh? It's only a cylinder.
#2
02/15/2009 (6:18 pm)
New issue I found. Please go to this link Here and help me out :)
#3
02/15/2009 (7:26 pm)
If your coin is something that can be picked up, just make it an item by copying item.cs and renaming it using your coin, without animation, to it. Torque will rotate it automatically for you. It can then also be picked up and added to inventory.
#4
02/15/2009 (7:30 pm)
Yeah, I want it to be picked up. I know how to add it to an inventory, thanks to the 'GettingStarted.pdf'I used along time ago. My question is, how can I get the engine to rotate the coin for me, thus making it more attractive & see-able? Would I include a animation within the file? Would I make a seperate '.dsq'? Or by Torque would do it for me, did you mean there is a way for the engine to automatically keep rotating things by using TorqueScript?
#5
02/16/2009 (5:09 am)
Yes. Torque will automatically rotate it for you.

Look in starter.fps/server/scripts/item.cs at the very bottom of the file and you'll see where rotation is set to true. Just make a copy of item.cs and rename it coin.cs or something along those lines.

In your new coin.cs, at the bottom, add a datablock for your coin along the lines of this:

datablock ItemData(myCoin)
{
   // Mission editor category, this datablock will show up in the
   // specified category under the "shapes" root category.
   category = "Coins"; // Shows up in the inspector under this name

   // Basic Item properties
   shapeFile = "~/data/shapes/items/myCoin.dts";
   mass = 0.7;
   friction = 0.8;
   elasticity = 0.3;


   respawnTime = 30 * 60000; // How long before the coin respawns

   // Dynamic properties defined by the scripts
   pickupName = "a coin"; // Prints to chat hud.
   value = 1; // How much is this coin worth?
};
That should get you going.
#6
02/16/2009 (6:43 am)
Torque will automatically rotate it for you -- so long as you treat your object as an Item with an ItemData datablock.

Have you noticed that weapons, ammo, healthpacks, etc, all rotate when they're placed in the world? That's just an "extra perk" for Items as opposed to say a StaticShape which would have to be animated.
#7
02/16/2009 (6:48 am)
Oh, ok. I never knew this. I always thought I had to make a animation to achieve this affect. Thanks. About the code:
datablock ItemData(myCoin)
{
   // Mission editor category, this datablock will show up in the
   // specified category under the "shapes" root category.
   category = "Coins"; // Shows up in the inspector under this name

   // Basic Item properties
   shapeFile = "~/data/shapes/items/myCoin.dts";
   mass = 0.7;
   friction = 0.8;
   elasticity = 0.3;


   respawnTime = 30 * 60000; // How long before the coin respawns [b]My
 coins are not going to respawn. Will the affect still work? [/b]

   // Dynamic properties defined by the scripts
   pickupName = "a coin"; // Prints to chat hud. [b] There is no chat hud
 in my game. The only time you receive messages is when I add a small 
fade in gui on a trigger. The affect can still work without using this  line
 of code? [/b]
   value = 1; // How much is this coin worth?
};
#8
02/16/2009 (7:07 am)
Quote:My
coins are not going to respawn. Will the affect still work?
Yes

Quote:There is no chat hud
in my game. The only time you receive messages is when I add a small
fade in gui on a trigger. The affect can still work without using this line
of code?
Yes.
#9
02/16/2009 (7:49 am)
Hmm, I made sure I executed my 'coin.cs' in 'game.cs'. Now, here is my updated 'coin.cs' script:
//-----------------------------------------------------------------------------
// Torque Game Engine 
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------
datablock ItemData(myCoin)
{
   // Mission editor category, this datablock will show up in the
   // specified category under the "shapes" root category.
   category = "coins"; // Shows up in the inspector under this name

   // Basic Item properties
   shapeFile = "~/data/shapes/coins/coin.dts";
   mass = 0.7;
   friction = 0.8;
   elasticity = 0.3;

   // Dynamic properties defined by the scripts
   value = 1; // How much is this coin worth?
}

{  // Let the coin rotate
   %obj = new Item() {
   dataBlock = %data;
   static = true;
   rotate = true;
  };
  return %obj;
}

function coin::onCollision(%this, %obj, %col) 
{ 
   if(%col.getClassName() $= "Player") 
   { 
      %client = %col.client; 
      %client.score++; 
      commandToClient(%client, 'SetScoreCounter', %client.score); 
      %obj.delete(); 
      %logoCount = logos.getCount(); 
      if(%logoCount > 0) 
        return; 
      // otherwise display victory screen 
      commandToClient(%client, 'ShowVictory', %client.score); 
   } 
}

Still, the 2 affects I would like to achieve are not happening. I want the coin to rotate and disappear on collision.
#10
02/16/2009 (8:19 am)
First off that code abounds with several errors -- look in your console while in game and look for them, or check the console.log. The script isn't being compiled and executed so the coin will not even show up under the "Coins" category in the editor. Second, if you are placing your coin in game then you're evidently using the shape from the "StaticShape" category which will not work like you expect.

There's a missing ; at the end of your datablock declaration.

This
{  // Let the coin rotate
   %obj = new Item() {
   dataBlock = %data;
   static = true;
   rotate = true;
  };
  return %obj;
}
is wrong as written but is also unnecessary since it's already there in item.cs.

Your function namespace doesn't match the name of your datablock or class -- thus nothing happens when you "collide" with it.

Try this:
datablock ItemData(myCoin)
{
   category = "coins"; // Shows up in the inspector under this name

   // Basic Item properties
   shapeFile = "~/data/shapes/buggy/wheel.dts"; //[b]change back to your shape![/b]
   mass = 0.7;
   friction = 0.8;
   elasticity = 0.3;

   // Dynamic properties defined by the scripts
   value = 1; // How much is this coin worth?
};

function myCoin::onCollision(%this, %obj, %col)
{
   if(%col.getClassName() $= "Player")
   {
      %client = %col.client;
      %client.score++;
      commandToClient(%client, 'SetScoreCounter', %client.score);
      %obj.delete(); // [b]since it's being deleted there's no need to worry about it respawning[/b]
      %logoCount = logos.getCount();
      if(%logoCount > 0)
        return;
      // otherwise display victory screen
      commandToClient(%client, 'ShowVictory', %client.score);
   }
}

You'll still need counting and scoring methods, but that will let your coins show up in the editor and be placed as ITEMS, you'll be able to "collide" with them, and they'll disappear forever.
#11
02/16/2009 (8:21 am)
Ahh thanks. About the destination, when I copied the code, I must have forgot some changes.

EDIT: Noob question. How do I get the coin to show up under Shapes then?
#12
02/16/2009 (10:49 am)
When your script get exec'd without errors, it will show up under shapes. If it isn't showing up, check your console.log to find out what errors you have.
#13
02/16/2009 (11:00 am)
It's showing up under 'Static Shapes'. And I also decided I'm going to continue with 'tutorial.base', as my game is small and not complex.
#14
02/16/2009 (11:14 am)
Static Shapes is the wrong category of "object" to place -- those work differently. Technically they're for non-interactive fixed-in-place simple objects.

The coin code, once corrected (see my last post), will cause the coin Item to show up under the Shapes -> coins category. From there you will see your desired and expected behavior.

Many people make the same mistakes about the type of shape they need to use. General rule of thumb is that if it takes a datablock and if you expect to do anything with it then it's a shape, if it doesn't need a datablock or scripted interaction then it's a staticShape.
#15
02/16/2009 (11:18 am)
Hmm. I can't find any errors dealing with shapes in the console. Is there a specific wording I should be looking for? Or a specific format for the coin?
#16
02/16/2009 (11:42 am)
Well, when I tried your code the first error I found caused a "parse" error, after fixing that one you will find another and a "syntax" error. Once all of those are corrected and the item shows up properly you won't be able to interact with it because the onCollision namespace does not match either the coins datablock name or it's class. This collision "error" won't cause a error warning though -- it simply doesn't happen.

Did you remember to delete DSOs before re-starting after "fixing" the code? Because the code example I fixed for you works for me. Without your actual coin shape I tested it with the buggy's wheel.dts so you'll have to change that back.

You model format should be DTS, and should have a collision mesh within it. When you place the "StaticShape" do you collide with it?
#17
02/16/2009 (11:49 am)
I modeled the coin in blender with no collision box around it. Does that mean I have to add one and re export it? And all the scripts I edited, you want me to delete the '.dso' for them?
#18
02/16/2009 (12:43 pm)
If you have no collision mesh, then it doesn't know if something "hit" it.

And yeah, anytime you modify any scripts you will need to delete the corresponding dso file. Torque "compiles" the scripts (xxx.cs) into byte code (xxx.dso), but only if the scripts contain no errors - most common being parse/syntax errors. Any of your new changes don't take effect until the old DSOs are removed and new ones are generated. You can remove them individual or there is a batch file that removes them in bulk. It's also good practice to routinely remove the various Torque generated pref & config files too.