0
\$\begingroup\$

I have a game character object which is followed by camera. Camera is child object of Character.

enter image description here

Using rigid body makes the character tilt in slopes and camera tilts too.

how do i stop camera tilting when character tilts?

\$\endgroup\$
1
\$\begingroup\$

The answer is in your second sentence.

Camera is child object of Character.

The Camera should not be a child of the character. This is what is causing the camera to tilt. A child will follow its parent's transform.

Remove the Camera from the Character. The script @Jon linked to will do what you want by modifying the camera transform, as the character moves without modifying rotation. So, your Camera shouldn't tilt at all.

If you need the camera to be a child of your character, @Jon offers another solution in the chat he links to that updates the Camera with an inverse rotation of your character.

\$\endgroup\$
  • 1
    \$\begingroup\$ Or, you can simply set the LocalRotation to 0, or whatever the initial value was. \$\endgroup\$ – jgallant Jan 19 '16 at 18:20
  • \$\begingroup\$ If the local rotation is zero, and it's linked to a spinning parent, it will still spin. Did you mean global rotation? \$\endgroup\$ – dval Jan 29 '16 at 17:03
  • \$\begingroup\$ No, local rotation of the gameobject, it will use the rotation of the parent object. You can then leave the object as the child if you did this. \$\endgroup\$ – jgallant Jan 29 '16 at 17:04
  • \$\begingroup\$ @Jon can you proivide any documentation on this, both this and this state the opposite. And a google search for 'unity rotate a parent without rotating child?' returns a lot of similar answers suggesting workarounds in reparenting. \$\endgroup\$ – dval Jan 29 '16 at 17:11
  • \$\begingroup\$ No I can't I just know that I've done this before. I wouldn't recommend it, as it is basically resetting the child's rotation on each frame. \$\endgroup\$ – jgallant Jan 29 '16 at 17:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.