- Home /
Making the character controller a child of another object
I am developing an application for a CAVE-type VR setup that uses head tracking. I need to make the first-person character controller a child of the head tracker so that it follows head movements. I have been able to make this work with regular GameObjects, but not with the character controller. I figure there must be something special about it that keeps it grounded.
Any suggestions of how I can make the controller behave more like a normal GameObject, specifically being able to pair it to other objects?
My code for reference:
public class AttachToHead : MonoBehaviour {
public GameObject node;
void Start () {
}
void Update (){
if (MiddleVR.VRDeviceMgr != null){
node = GameObject.Find("HeadNode");
this.transform.parent = node.transform;
}
}
}
I don't think you need to know anything about MiddleVR for this question. This code works as expected for GameObjects.
Answer by Stygtand · Jun 06, 2014 at 05:21 PM
Just to clarify, you want AttachToHead to be parent of node?
Try to debug. Can you even find the game object
if (MiddleVR.VRDeviceMgr != null){
Debug.Log(MiddleVR.VRDeviceMgr);
node = GameObject.Find("HeadNode");
Debug.Log(node);
this.transform.parent = node.transform;
}
if its not null, you found it and it will parent it.
Actually, it's the opposite. I want AttachToHead to be the child of node.
It finds the GameObject. I know this because I had this script attached to a cube, which made the cube the child of "HeadNode" (the head tracker). When I moved the tracker the cube moved as well. This is what I want it to do, only with a character controller.
Then do the other way around. http://docs.unity3d.com/ScriptReference/Transform-parent.html
node.transform.parent = transform;
Your answer

Follow this Question
Related Questions
After unchilding a Character controller, it becomes disoriented 0 Answers
Make a simple tree 1 Answer
Making Rigidbodies the parent of character controllers is giving me problems. 1 Answer
Use Parent to fix the rotation of character 1 Answer
Character controller moves slow when an object its parented 1 Answer