- Home /
help with my orbit camera script
I need help with my orbit camera script.
I extended the script so that on clicking the mouse on a point the orbit camera will re-centre to that position. This works fine and when i click the new point the camera translates to the new point.
The orbit camera works by the following method. X and Y are spherical co-ordinates with orbitRadius as the radius. x and y are calculated from mouse or gestures in the app.
camera.rotation = Quaternion.Slerp( rotation, Quaternion.Euler(y, x, 0), Time.deltaTime * 6.0f);
Vector3 position = rotation * new Vector3(0, 0, -orbitRadius) + orbitCentre.position;
camera.transform.rotation = rotation;
camera.transform.position = position;
to translate between the new centre position
deltaTargetMove = Vector3.MoveTowards(orbitCentre.transform.localPosition, newOrbitCentre, 12.0f * Time.deltaTime);
orbitCentre.transform.localPosition = deltaTargetMove;
The current behaviour is the camera translates at a fixed distance from the moving centre point. The issue is i want to edit the behaviour so that when i click a new position the camera stays in the same location but the camera rotates to focus on the new centre location. so in effect i need to increase the orbitRadius distance during the transition and edit the x and y calues.
I do not know the best method to do this ? i have attempted many solutions but they all have failed
I'm a bit confused by the question, but I have created a camera system like this in the past. You said you want the camera to remain stationary and only rotate when the player clicks? Is the player click actually moving the character, and you want the camera to rotate within the sphere to point at the new location where the character is moving toward?