-1

I am building a 3rd Person game in Unity and I have it so the Camera is attached to the head. The head rotates when my mouse moves, right now the head can do 360s while the body does not move.
My objective here is to rotate the whole body(parent object) when the head rotates 45 degrees left/right. I have no clue what I am doing but here is my code for this object so far...

http://pastebin.com/S9Y5iPDM

I don't receive any errors, it's just that nothing happens.

HoloLady
  • 1,041
  • 1
  • 12
  • 28

1 Answers1

0

You can use :

transform.parent //if the script in head.

(or)

reference.transform.parent //if you are getting reference for the gameObject(reference should be replaced with the name of the reference gameObject name)

But some problem will come when you move your body. It will add extra rotation to entire game object.

Problem you may face

ie if you are looking at 45 degree. Then you rotate body it will rotate head with it. So Head will have 45 degree rotation and so the body. At the total of 90 degree.

Solution

rotate the body with the same amount rotated(Y axis) in head. and then make the head rotation to 0. Use Vector3.lerp or it will jitter or jerk in screen view.

Sundar Bons
  • 111
  • 1
  • 1
  • 10