- Home /
How to freeze rotation of the camera
Hello everyone. I have a problem about rotations of my camera. I have a cannon and it fires a ball. And I want my camera to follow the fired ball, and watch where the ball hits. So I did something like that :
var newBall = Instantiate(ball,ballSpawn.transform.position,ballSpawn.transform.rotation);
newBall.rigidbody.velocity = ballSpawn.transform.TransformDirection ( Vector3.forward * power * Time.deltaTime * 100 );
cameraObject.transform.parent = newBall.transform;
it works, but when the ball hits the floor, ball starts to roll. ( it's a simple sphere with rigidbody ) So as long as ball rolls, camera rolls to. What I want is, camera will not change it's position according to the instantiated ball object, it'll just follow it. Any ideas ? Thanks :)
not sure , try isolating the transform on the camera to just transform.position
Answer by fafase · Apr 15, 2012 at 04:32 PM
You are passing the whole transform,
cameraObject.transform.parent = newBall.transform;
using parent is making it a child so it inherits all transform.
You could instead get the camera and simply alter the position
cam = GameObject.Find("MainCamera");
cam.transform.position = newBall.transform.position;
Your answer
Follow this Question
Related Questions
Rotating camera problem C# Android 2 Answers
Camera following/looking at aircraft 1 Answer
Camera not rotate when following player 1 Answer
Camera that sits behind player 2 Answers
Minimap rotation 2 Answers