- Home /
Why is my Camera rotating?
FYI i am using unity 4.3 and im making a 2d game using the 2d mode in unity.
As you can see in the picture, every time i run the game it runs fine but after a few seconds the camera just rotate away. i have no idea why this is happening it will very helpful if you guys can help me. do i need a camera script? im using c#.
Answer by Statement · Dec 22, 2013 at 04:02 PM
It's rotating because it's parented to a rotating ball.
I'd suggest you
Unparent the camera
Write a simple script that follows the position of the ball
Attach the script to the camera
A super simple script that can be placed on the camera is as follows:
using UnityEngine;
public class Follow : MonoBehaviour {
public Transform target;
void LateUpdate () {
if (target)
transform.position = target.position;
else
Debug.LogWarning ("You forgot to set the target", this);
}
}
You'll need to set the target to the ball for it to work. If you need an offset, add a variable for it or just place this on an empty game object and parent your camera onto that game object and offset it via the inspector (change position).
Answer by Gusic · Dec 22, 2013 at 04:25 PM
I have fixed the problem but thank you. I now have a very big problem when I move my character forward and jump but a couple seconds latter the ball goes the opposite direction all of the sudden and the floats away randomly I am so confused
Your answer
Follow this Question
Related Questions
First Person Camera not being child of the character/ Set child's rotation to global rotation 2 Answers
How do I have a Child tell a Parent to move without the Child itself moving 0 Answers
How to activate parent camera of gameobject -1 Answers
Unity2D button as child of camera not clickable 1 Answer
Multiple cameras as child or assign coords/rot to main cam 1 Answer