- Home /
Make Child face direction of analog RELATIVE to parent's direction
As the titles suggests, how do I make a child object face the direction of the analog stick I'm pressing relative to the parent's position?
Here is my code
var dir = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
var rDir = new Vector3(Input.GetAxis("Horizontal2"), 0, 0);
//Vector3 test = transform.TransformPoint(dir);
//print ("test: " + test);
if(rDir.x != 0)
{
transform.Rotate(Vector3.up * rDir.x * cmv.rotateSpeed * Time.deltaTime);
}
else
{
transform.Rotate(Vector3.up * 0);
}
if(cmv.moveDirection.x == 0 && cmv.moveDirection.z == 0)
{
mv.model.transform.forward = transform.forward;
}
else if (cmv.moveDirection != Vector3.zero)
{
mv.model.transform.forward = Vector3.Normalize(dir);
}
I rotate with the right analog stick and that's what the Horizontal2 is, that works fine and the child faces the direction of the parent object while rotating.
When I tell the child object to face dir, that dir gets a Vector3 based on the input of the left analog stick. The problem is that this Vector3 is relative to the world space. How do I convert this Vector3 from world space relativity to local relativity?
Your answer
Follow this Question
Related Questions
Why is a child object not rotating properly with parent? 1 Answer
First Person Camera not being child of the character/ Set child's rotation to global rotation 2 Answers
Freeze specific rotation axis of a child 2 Answers
rotate parent object to straighten child object? 2 Answers
Player Rotation Snapping 1 Answer