Game Development Community

Dynamic object placement

by Vincent Ellis · in Torque 3D Beginner · 09/19/2013 (2:16 pm) · 3 replies

I'm looking for a way to place objects dynamically in-game... like in an RTS game, but from the first person perspective. Is it possible to spawn objects where the user is aiming? Something like this:

http://www.youtube.com/watch?v=uzcnhbDKM_A

#1
09/19/2013 (2:22 pm)
"Anything is possible"... no really.. it is :)

Just use some vector math from where the player is looking, or use a raycast to determine the spawning location. You'll need to schedule a call to a function that uses the player as a parameter to obtain the location of the player and to actually spawn the object, add some randomness to it with the lovely getRandom() function and voila, objects spawning where you're aiming!
#2
09/20/2013 (5:05 am)
Vincent.

Try the following tutorial, it shows you how to place an orc house on the terrain where the mouse is clicked:
http://docs.garagegames.com/torque-3d/official/content/documentation/Scripting/Advanced/RTSPrototype.html

If you want to have it work in FPS, just need to change it so that instead of the position of the mouse cursor you use the middle of the screen.
#3
09/20/2013 (6:40 am)
Quote:If you want to have it work in FPS, just need to change it so that instead of the position of the mouse cursor you use the middle of the screen.

Or the eye vector - just scale it up.