Renegade Public Forums
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
Home » Renegade Discussions » Mod Forum » distance between two objects c++
distance between two objects c++ [message #432316] Thu, 08 July 2010 04:37 Go to previous message
reborn is currently offline  reborn
Messages: 3231
Registered: September 2004
Location: uk - london
Karma:
General (3 Stars)
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

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: C++ void On_Player_Death???
Next Topic: proximity speech
Goto Forum:
  


Current Time: Sun Oct 27 16:35:04 MST 2024

Total time taken to generate the page: 0.01186 seconds