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\$
13
  • 5
    \$\begingroup\$ Possible duplicate of How do I have a camera follow my object in Unity? \$\endgroup\$
    – jgallant
    Commented Jan 19, 2016 at 16:08
  • 1
    \$\begingroup\$ @Jon no it isn't duplicate. My problem is clearly written in the question. \$\endgroup\$
    – user75648
    Commented Jan 19, 2016 at 16:10
  • 3
    \$\begingroup\$ I disagree. Your answer is definitely in that link, the top voted answer. \$\endgroup\$
    – jgallant
    Commented Jan 19, 2016 at 16:11
  • \$\begingroup\$ Couldn't find the exact thing i want. Please direct me. \$\endgroup\$
    – user75648
    Commented Jan 19, 2016 at 16:42
  • \$\begingroup\$ gamedev.stackexchange.com/a/86376/10728 \$\endgroup\$
    – jgallant
    Commented Jan 19, 2016 at 16:53

1 Answer 1

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\$
5
  • 1
    \$\begingroup\$ Or, you can simply set the LocalRotation to 0, or whatever the initial value was. \$\endgroup\$
    – jgallant
    Commented Jan 19, 2016 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
    Commented Jan 29, 2016 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
    Commented Jan 29, 2016 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
    Commented Jan 29, 2016 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
    Commented Jan 29, 2016 at 17:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .