Add animated itemData shapes to gameworld
by Brian Carlson · 06/09/2009 (1:16 pm) · 4 comments
Here's a little resource for adding animated itemData shapes in starter.fps. It's really very simple, but I was having trouble with it, so I decided to make a resource for it. Note that this would probably come right after that Getting Started guide. The goal of this is to take an animated model in get it into the game. I made a little gold coin. From here, and using the the Getting Started guide, you should be able to add a counter as well.
Here's what to do:
Create the model and animate it, exporting the .dts shape, .dsq animation, and .cs TSShapeConstructor datablock. I put all three plus the texture in "~datashapesitems"
Open health.cs in "~serverscripts" and copy and paste the HealthPatch datablock and its onCollision function (if you want to interact with it). Replace 'datablock ItemData(HealthPatch)' with datablock ItemData(goldCoin)', and 'function HealthPatch::onCollision(%this,%obj,%col)' with 'function goldCoin::onCollision(%this,%obj,%col)'. Change "Health" in 'category' to "Coins". This will create a new folder when in the World Editor Creator. Change the shapefile pathname to the new .dts file since we're replacing the HealthPatch. In the onCollission function, I also added '%obj.delete();' at the end. Otherwise, you can 'collect' coins by running into them, but they never actually get removed from the world. There's one more thing to do in this file. Create an onAdd function for the datablock. This will allow you to make events to happen when the coin is added.
For example, a counter. Rather than keep track of how many I placed in the world with the World Creator, when the mission file runs, every time one of the coins are added to the world, it increments a global variable. In this resource at least, all it will be doing is calling playThread to make the animation run. If you named the animation something different when exporting the .dsq, just use that. It should work just fine.
Finally, in "~server/scrips/game.cs", at the end of the list of .cs file executions, I added my own to execute that .cs file with the shapefile name and animation in it. It should have the same name as the shape, but a .cs script. This is an execution from a file in the 'server' to one in the client, so it may violate that separation of client and server that's so important in Torque, so I'd appreciate if a more experienced user commented on this. Anyway, here's what I wrote to load that file:
exec("~/data/shapes/items/goldCoin.cs");
At the end of this, you should be able to go into the game, press F11, choose World Editor Creator, and in the bottom right, choose 'Shapes,' 'Coins,' and just click on 'goldCoin' to add it to your level. Add as many as you want. Be sure to save the mission file when you are done.
Here's what to do:
Create the model and animate it, exporting the .dts shape, .dsq animation, and .cs TSShapeConstructor datablock. I put all three plus the texture in "~datashapesitems"
Open health.cs in "~serverscripts" and copy and paste the HealthPatch datablock and its onCollision function (if you want to interact with it). Replace 'datablock ItemData(HealthPatch)' with datablock ItemData(goldCoin)', and 'function HealthPatch::onCollision(%this,%obj,%col)' with 'function goldCoin::onCollision(%this,%obj,%col)'. Change "Health" in 'category' to "Coins". This will create a new folder when in the World Editor Creator. Change the shapefile pathname to the new .dts file since we're replacing the HealthPatch. In the onCollission function, I also added '%obj.delete();' at the end. Otherwise, you can 'collect' coins by running into them, but they never actually get removed from the world. There's one more thing to do in this file. Create an onAdd function for the datablock. This will allow you to make events to happen when the coin is added.
function goldCoin::onAdd(%this,%obj)
{
%obj.playThread(0,"root");
} For example, a counter. Rather than keep track of how many I placed in the world with the World Creator, when the mission file runs, every time one of the coins are added to the world, it increments a global variable. In this resource at least, all it will be doing is calling playThread to make the animation run. If you named the animation something different when exporting the .dsq, just use that. It should work just fine.
Finally, in "~server/scrips/game.cs", at the end of the list of .cs file executions, I added my own to execute that .cs file with the shapefile name and animation in it. It should have the same name as the shape, but a .cs script. This is an execution from a file in the 'server' to one in the client, so it may violate that separation of client and server that's so important in Torque, so I'd appreciate if a more experienced user commented on this. Anyway, here's what I wrote to load that file:
exec("~/data/shapes/items/goldCoin.cs");
At the end of this, you should be able to go into the game, press F11, choose World Editor Creator, and in the bottom right, choose 'Shapes,' 'Coins,' and just click on 'goldCoin' to add it to your level. Add as many as you want. Be sure to save the mission file when you are done.
#2
How about an art tutorial on animating the shape and exporting the .dsq?
Thanks!
Tony
06/10/2009 (5:20 am)
Very nice! An excellent supplement to the gettingStarted.pdf tutorial.Quote:
Create the model and animate it, exporting the .dts shape, .dsq animation, and .cs TSShapeConstructor datablock. I put all three plus the texture in "~datashapesitems"
How about an art tutorial on animating the shape and exporting the .dsq?
Thanks!
Tony
#3
06/10/2009 (11:36 pm)
If I remember correctly, if you have an animation named ambient it will be played automatically on creation. Also for items that usually end up being props most people just compile the animations in the dts. Then you don't have to worry about missing dsq files.
#4
06/26/2009 (12:18 pm)
Yeah, I use embedded ambient animations all the time, but I've never been able to export a .dsq properly.
Torque 3D Owner Novack
CyberianSoftware
This would be a good complimentary lecture: Plastic Gem #1: Placeable Shapes.