- Home /
Find gameobject furthest from player along z axis
I have an array of character bones. I would like to know which bone is the furthest from the character root along the positive z axis (backward distance should be ignored). Since the bones will keep moving, the furthest one will keep changing and therefore the variable holding the furthest bones will need to be continuously updated.
How can I find which of the bones in the array is the furthest along the positive z axis from the character root?
Here is my code so far:
public GameObject[] allBonesToCheck;
public GameObject characterRoot;
private GameObject furthestBone;
// Update is called once per frame
void Update()
{
FindFurthestBone(allBonesToCheck);
}
GameObject FindFurthestBone(GameObject[] allBonesToCheck)
{
float FurthestDistance = 0;
GameObject furthestBoneTemp = null;
foreach (GameObject Object in allBonesToCheck)
{
//Compare positive z distance of each bone to character root
//Find furthest bone along positive z axis from character root
}
furthestBone = furthestBoneTemp;
}
screenshot-22-03-2020.png
(8.0 kB)
Comment