- Home /
Solved the problem myself
Camera follow ball along cylinder
In my game I have a ball that rolls along a cylinder and can also rotate around it.
The camera script I currently have looks like this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraController : MonoBehaviour
{
private GameObject player;
private Vector3 offsetPosition;
void Start()
{
player = GameObject.FindGameObjectWithTag("Player");
offsetPosition = transform.position - player.transform.position;
}
void LateUpdate()
{
transform.position = player.transform.position + offsetPosition;
}
}
So it simply follows the ball. When I rotate the ball around the cylinder it looks like this
How can I modify the camera script so the camera view stays the same and rotates with the ball around the cylinder?
Picture might help, also you don't usually make your camera(s) as children of the thing they're following. UA's pretty good for short, direct questions, so you might want to help the readers by being explicit about the behavior you're trying to achieve.
Answer by inspired997 · Mar 02, 2020 at 10:49 AM
Hello, have you managed to solve this problem? I need it in the same way. Thanks :)
To move the camera I used private void FixedUpdate() { transform.position = transform.position + movement * speed * Time.deltaTime; }
movement is your directional vector. And when you want to rotate you use transform.rotate(). Hope that could help.