- Home /
Roll-a-Ball Tutorial Camera still doing loop de loop as it follows the sphere.
Hi everyone. I followed the exact steps for the Roll-a-Ball tutorial and I was able to affix my camera to the sphere but it is still doing a rotation (a vertical rotation around the z-axis) as I'm moving the sphere. I am using a prefab of a beach ball I downloaded from the assets store, could some setting in there be affecting it?
How are you doing the following? Is the camera a child object?
Answer by cat_dawg · May 10, 2021 at 04:56 PM
Hi @GSGregory! No, I didn't make it a child object. The camera is its own game object with a camera controller script attached. The following script is directly from Unity's tutorial on YouTube.
public class CameraController : MonoBehaviour { public GameObject player;
private Vector3 offset;
void Start()
{
offset = transform.position - player.transform.position;
}
// Update is called once per frame
void Update()
{
}
void LateUpdate()
{
transform.position = player.transform.position + offset;
}
Hmm. I'm looking at the tutorial currently and trying to figure out what the issue is. In the meantime this is the script I currently use to manage my own camera.
{
public GameObject target;
public Vector3 offset;
public Transform targetTransform;
public float offsetMax = 20f;
public float offsetMin = 10f;
// Update is called once per frame
void LateUpdate()
{
transform.position = target.transform.position + offset;
transform.LookAt(targetTransform);
if (Input.mouseScrollDelta.y > 0 && offset.y < offsetMax)
{
offset.y += Input.mouseScrollDelta.y;
}
if (Input.mouseScrollDelta.y < 0 && offset.y > offsetMin)
{
offset.y += Input.mouseScrollDelta.y;
}
}
}
Btw, what is the offset set to?
Yes, of course! I got it from the Assets store.
https://assetstore.unity.com/packages/3d/props/free-beach-essentials-asset-pack-131149
Thank you so much for your help so far. I'm completely brand new to this!
I apologize if I answer thing in the wrong terms:
If by offset, do you mean the difference between the player's position and the camera's position...could I answer that by listing the vectors? I don't think I have offset set to anything... The position of my object is (-323, 70, -49), the camera is (-323, 89, -68) rotated at 45 degrees on the x-axis.
I also tried your script without messing with any values and it's still doing that weird rolling motion as I move the ball. So strange!
Your answer
Follow this Question
Related Questions
Camera And player rotation 0 Answers
Third person follow camera on a sphere 1 Answer
"Free" rotation about a sphere 0 Answers
Camera/Direction Rotation 2 Answers
Camera rotation around the sphere 0 Answers