Is there a way to cycle through the world's objects?
by Brian Westgate · in Technical Issues · 01/06/2011 (12:10 am) · 1 replies
Scenario:
I have 5 TSStatic trees in a level.
Is there a way to cycle through all of these trees in a script to obtain their information (location x,y,z) or alter their information (location)? What I am looking to do is to cycle through all the objects of my map to then check their proximity to the player's current position. Also, if you happen to know a way to obtain a player's location that would also be helpful. I'm building off of the FPS template that came with the demo. Thank you.
I have 5 TSStatic trees in a level.
Is there a way to cycle through all of these trees in a script to obtain their information (location x,y,z) or alter their information (location)? What I am looking to do is to cycle through all the objects of my map to then check their proximity to the player's current position. Also, if you happen to know a way to obtain a player's location that would also be helpful. I'm building off of the FPS template that came with the demo. Thank you.
Torque Owner Robert Fritzen
Phantom Games Development
You'll want to cycle through the MissionCleanup group and perform a similar datablock check.
function Distance(%player) { if(!isObject(%player) || %player.getState() $= "dead") { //don't check dead people. return; } %closest = 999999; %myPosition = %player.getPosition(); %group = MissionCleanup; for(%i = 0; %i < %group.getCount(); %i++) { %object = %group.getMember(%i); //do datablock check here if(vectorDist(%object.getPosition(), %myPosition) < %closest) { if(%object != %player) { //don't check yourself silly! %closest = vectorDist(%object.getPosition(), %myPosition); %closestObj = %object; } } } }You could definitely expand off of that. That contains pretty much most of what you wanted, you'll just need to do the datablock check.