by Benzi Avrumi
Last Updated November 09, 2018 00:13 AM

I'm trying now:

```
foreach (GameObject obj in allobj)
{
CompareTransformsData(obj) == false)
}
```

The method: CompareTransformsData

```
public static bool CompareTransformsData(GameObject objToCompare)
{
List<GameObject> results = allobj;
bool identical = true;
foreach(GameObject obj in results)
{
if (GameObject.ReferenceEquals(obj, objToCompare))
{
return identical;
}
}
return identical;
}
```

What I want to do is to check if obj is identical to any of the gameobjects in allobj.

The first problem is the loop I guess I'm checking the same objects and messed it all.

Second problem the comparison is wrong since comparing floats never accurate.

I was noticed and saw that maybe I should do this: But I'm not sure how to do it in my code.

"You are not getting desired result because of the comparers. You should not compare floating point values/Vectors/Quaternions using "==". As they are based on floats & many a times they wont be accurate enough. Even the cloned objects will have float values 1.000001 or 0.999999.

The better option would be for vectors use "Vector3.distance" or "Vector3.Equals" and for Quternions you can use "Quaternion.Angle" or Quaternion.Equals to check the corresponding result.

ie obj.transform.position.Equals(objToCompare.transform.position) & obj.transform.quaternion.Equals(objToCompare.transform.quaternion). This should return the proper results but there is a chance that the results might not come up same if that happens you can use

ie Vector3.Distance(obj.transform.position, objToCompare.transform.position) < "Margin of difference". Quaternion.Angle(transform.rotation, rotation)<"Margin of difference"

You can specify your own value like for margin of difference you would allow."

- Serverfault Help
- Superuser Help
- Ubuntu Help
- Webapps Help
- Webmasters Help
- Programmers Help
- Dba Help
- Drupal Help
- Wordpress Help
- Magento Help
- Joomla Help
- Android Help
- Apple Help
- Game Help
- Gaming Help
- Blender Help
- Ux Help
- Cooking Help
- Photo Help
- Stats Help
- Math Help
- Diy Help
- Gis Help
- Tex Help
- Meta Help
- Electronics Help
- Stackoverflow Help
- Bitcoin Help
- Ethereum Help