So in my scene hierarchy, I have an object laid out like so; -Level1 --Level2 ---Level3 ----Level4
My script is attached to the Level1 object. When I try to find the transform.position of Level4 by way of Debug.Log to the console, I get the position of Level1, and so when I change the position of Level4 inside Level3, the data sent to the console doesn't change, still shows the position of Level1.
I do not believe this may be relevant, but what I am doing is an IK rig to move a character's limb. The object for which I am attempting to find the position is nested inside the skeleton of the character. The value returned to me is the position of the prefab placed in the scene. All of the objects (Level1 through Level4) are not explicitly moved, however they inherit their positions from the rotation of their parent.
My code to read the position is as follows:
Debug.Log(object.position);
Where object is already a transform. I have also tried:
Debug.Log(object.transform.position);
But still, all I get is the position of the top level parent.
Thanks for any help.
ADDITION
Ok so to expand on the question, I'll explain exactly what I'm trying to do. I have the mecanim example and unity 5.0.1f1. I have the Mecanim Example project from the asset store and I'm in the animator controller scene. I have enabled IK pass on my base layer, and have placed my code in the "idle run jump" script, attached to the top level of the game object for the playable character. I have then attached an empty game object inside the left foot to mark the location of where the left heel meets the floor. This object is attached in the inspector to a variable in the "idle run jump" script, which then receives the ik pass through the function OnAnimatorIK. My aim is to get the foot to follow the same position as another object, where leftFoot follows leftFootObj. My code is as follows;
using UnityEngine;
using System.Collections;
public class pos : MonoBehaviour {
protected Animator animator;
public float offset = 0.156f;
public Transform leftFoot;
public Transform leftFootObj;
void OnAnimatorIK() {
if (animator == null)
return;
if (leftFoot != null) {
Debug.Log(leftFoot.position);
animator.SetIKPositionWeight(AvatarIKGoal.LeftFoot,1);
animator.SetIKRotationWeight(AvatarIKGoal.LeftFoot,1);
animator.SetIKPosition(AvatarIKGoal.LeftFoot,(leftFootObj.position+(Vector3.up*offset)));
animator.SetIKRotation(AvatarIKGoal.LeftFoot,leftFootObj.rotation);
}
}
void Start ()
{
animator = GetComponent<Animator>();
if(animator.layerCount >= 2)
animator.SetLayerWeight(1, 1);
}
}
Debug.Log(object.position);
is attached to the nested Lvl4 object I presume? did you tryDebug.Log(this.transform.position);
\$\endgroup\$