Making the camera rotation in line with the ball
Hi,
I have 3d ball player object that travels inside a 3d pipe. It is followed by a camera. At the moment, as the ball goes from side to side, the camera rotation does not change. What I am trying to achieve is that camera rotates along the single axis in line with the ball's position on the wall of the pipe.
Current set up:
What I am trying to achieve is this:
My current code is as follows:
public class CameraFollow : MonoBehaviour
{
public GameObject ball;
// Start is called before the first frame update
private Vector3 _offset;
void Awake()
{
_offset = new Vector3(10,5, 0);
}
// Update is called once per frame
void FixedUpdate()
{
transform.position = ball.transform.position + _offset;
transform.LookAt(ball.transform);
}
}
I tried using euler angles but it did not work as intended. I am sure the solution is fairly straightforward but I just don't get it. Any help would be appreciated.
Answer by cam74 · Jun 14, 2020 at 09:26 PM
Can't you set it as a children of the ball?
I have solved this problem by reference to collision normals of the pipe (Thank you, Jason Weimann).
I cannot make it a child because as the ball rolls, the camera will roll with it - the rotation of the camera will reflect the rotation of the ball.
Your answer
Follow this Question
Related Questions
CineMachine Camera Movement is inverse 1 Answer
C# Smooth Follow Space Ship 1 Answer
Spyro Like Camera Follow 0 Answers
When attaching my custom camera script camera shakes when player starts to move fast. 1 Answer
Camera Roll/Headbob? 0 Answers