camera rotating crazily around a rolling ball on a slope

Hi i have a similar question to this here… i tried Halmato’s answer and it didnt work how i wanted it to… here’s a video about the problem: (ball physics - YouTube) i just want the camera to have a normal mouse rotation while the ball is rolling and whatever physics its doing,

Glad I could help!

3 Answers

3

@supremegamer76

Hi there,

I guess you added your camera as a child object of your player.
As your ball rotates, so does the camera
The tutorial 2D UFO covers that same problem in the video 5/9 "Following the player with the camera. (link below)

They create a code you have to add to your camera (not attached to player anymore if I remember correctly).
Not too complicated even if English isn’t your mothertongue as it is my case.

And just below the video is the code.

Hope it helped.

Ok so i added in the code, the issue is that i want it from a 3rd person perspective, and it put the camera as a 1st perspective camera... i want it so that i can be in 3rd person directly about 2-3ish away behind where the ball is facing and about 1 above and looking down at an angle, but i dont want it to tilt sideways when the ball is on a slope... and when the ball rotates, the camera will rotate around the ball at the same distance. i don't want the camera to be a child of the ball because the thing will happen as shown in the video.

That happens because your camera is the child of the ball and will always stay in same position when compared to the parent object.

I would make new empty game object and script for it so it will always be exactly in same position as the ball and then make the camera child of this object. When you rotate the ball on Y-axis you should also rotate this empty parent object so it will rotate the camera. This way when the ball starts rolling the camera won’t follow it’s rotation like it does now.

In your case it seems to make sense to stop Unity from solving rotations when its rigidbody collides. In your sphere’s Rigidbody component go to Constraints and set Freeze Rotation X, Y and Z to true.
Done this you should be able to set your own rotation in your Update/FixedUpdate/LateUpdate function.