Someone asked me about setting a conditional that checked whether the distance between two objects was lower than 40 metres. They aaked me privately and for it in LUA, but I prefer this in the public domain, there could be others that have the same question or maybe someone else might have something useful to add...
Besides, they also said they would of posted the question in another forum that is public, so go figure? Fucking leachers!
I do not know how to write this in LUA, but here it is in C++:
//obj1 and obj2 are the Two GameObject's you're comparing.
float Dist;
Vector3 pos1, pos2;
pos1 = Commands->Get_Position(obj1);
pos2 = Commands->Get_Position(obj2);
Dist = Commands->Get_Distance(pos1, pos2);
if(Dist <= 40.0f){ // If the distance is less than 40 metres
// do something
}
else{ // Distance is greater than 40 metres
// do nothing?
}
or:
float Dist = Commands->Get_Distance(Commands->Get_Position(obj1),Commands->Get_Position(obj2));
if(Dist <= 40.0f){ // If the distance is less than 40 metres
// do something
}
else{ // Distance is greater than 40 metres
// do nothing?
}
or:
if((Commands->Get_Distance(Commands->Get_Position(obj1),Commands->Get_Position(obj2))) <= 40.0f){ // If the distance is less than 40 metres
// do something
}
All of the above should work (not tested), but each show you basically the same thing using less lines.
[Updated on: Fri, 09 July 2010 13:09]
Report message to a moderator