- Home /
Camera script for ball not working as intended, looking for some tips, or advise.
New to Unity, just got into it possible 3 days ago and wanted to do a little side project while I was studying to the engine and its libraries.
At the moment however I am stuck and am not really sure how to proceed with this issue I have.
The camera is behaving how I would like it to. Sticking behind the ball like a third person view. Staying in the same y position and allowing viewing with the mouse to look around. However im not able to move forward in the direction the camera is facing.
For Example: I'd be moving forward, but when my camera is facing behind or to the left while holding the W key, it will still be heading in the same direction instead of where the camera is facing. I believe that im supposed to change the transform for the player or something along those lines, but what i've tried hasn't worked for me yet.
I'd love it so much if you guys could let me know what I could be doing wrong with this Camera script.
private const float Y_ANGLE_$$anonymous$$IN = -50.0f;
private const float Y_ANGLE_$$anonymous$$AX = 50.0f;
public Transform lookAt;
public Transform camTransform;
private Camera cam;
private float distance = 4.0f;
private float currentX = 0.0f;
private float currentY = 0.0f;
void Start()
{
camTransform = transform;
cam = Camera.main;
}
void Update()
{
currentX += Input.GetAxis("$$anonymous$$ouse X");
currentY += Input.GetAxis("$$anonymous$$ouse Y");
currentY = $$anonymous$$athf.Clamp(currentY, Y_ANGLE_$$anonymous$$IN, Y_ANGLE_$$anonymous$$AX);
Vector3 dir = new Vector3(0, 3, -distance);
Quaternion rotation = Quaternion.Euler(currentY, currentX, 0);
camTransform.position = lookAt.position + rotation * dir;
camTransform.LookAt(lookAt.position);
}
Your answer
Follow this Question
Related Questions
How can I get a Capsule to move and rotate in the direction the cam is facing? 1 Answer
Auto-Scrolling Level - crushing player results in death 0 Answers
Rotate camera around object and let it centered 0 Answers
Simple Third Person Camera-Relative Movement with WASD - kind of working but need a fix 2 Answers
WASD Movement and rotates with mouse 1 Answer