Game Development Community

how to spawn an item in the game?

by Vince Gee · in Torque 3D Professional · 03/08/2011 (11:36 am) · 2 replies

Ok,

I must be an idiot, but for the life of me I can't figure out how to do this.

I want the user to click a button and have it drop an object at their feet in the game.

Could someone post the code for something like this?

Vince

#1
03/08/2011 (12:20 pm)
Check out the stock "throw" function for how the stock project/FPS example spawns the items the player is carrying on their death.
#2
03/08/2011 (12:28 pm)
I know Steve already gave you an answer, but since i was writing this i might as well post it :P

This depends what type of item you're talking about. At least for all classes that uses datablocks, this should work:

%obj = new ClassNameHere() {
      dataBlock = DataBlockNameHere;
   };
%obj.setTransform(%player.getTransform());
Note that some classes will fail to setTransform and scope to the clients. In those cases you could get the position before creating the object, and then use it as position = %pos; in the new object.

Remember to replace ClassNameHere with the type of class you want to spawn, and the DataBlockNameHere with the name of the datablock.

If you need any more functions (key mapping, commandToServer, etc) just tell me.