Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more..
    Dismiss Notice
  3. Dismiss Notice

Rotating camera!!!

Discussion in '2D' started by Pigion07, Jan 10, 2021.

  1. Pigion07

    Pigion07

    Joined:
    Jan 10, 2021
    Posts:
    2
    Hello, i am a very beginner in unity.
    I started to create something what does move:)))
    so i have a Character(avatar) wich is suppose to act like Mario. jumping, etc.
    but when i hit play, the camera is rotating with the character
    only when is child of the character.
    if is not child, camera doesnt follow the character,
    why camera is rotating? :)))
    btw, the character is a cube,
    and why the CUBE is rotating.?
     

    Attached Files:

  2. Derekloffin

    Derekloffin

    Joined:
    Mar 14, 2018
    Posts:
    322
    All children of an object will rotate with their parent, so that's why you're getting the rotation.
    There is quite a few ways to do this without getting the rotation. You can keep the two separate and add a script to the camera, on update, to adjust its position to match the player (that's generally the solution I've seen used most). Alternately could make the camera the parent, and do all x y motion on the camera but rotation on the child player. It would work, but its devious and I wouldn't recommend it. Another similar possibility is to counter the rotation on the camera, so the two rotations cancel out Again, don't recommend it for the same reason. The first method is very straight forward and obvious what it is doing.
     
  3. Pigion07

    Pigion07

    Joined:
    Jan 10, 2021
    Posts:
    2
    but why the cube is rotating? it`s a cube that is suppose to slide, and jump. not rotating, and the camera to follow the cube... :))))
     
  4. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    If the cube has a Rigidbody2D on it, it will follow the physics engine.
    It's likely rotating when it falls off a platform, in the same way that objects rotate when they fall off any surface in real life.

    In the Rigidbody2D's inspector, expand the "Constraints" option and check the "Z" box next to "Freeze Rotation". This will prevent external forces from rotating the object.