Tilting a camera around an object
My goal is to have a central object where the camera will tilt to the left and right of it while also rotating to get a view of the object using the A and D keys. I've tried this a few ways so far, just rotating the camera (went horrible), lerping (went better but was kind of hard to wrap my head), and move towards (didn't have the smooth effect of lerping).
I also want the camera to snap back into its original location after the A or D key is released. So I'm just hoping to get a better understanding of what the best thing I can use here is. Been working on this for like 2 days now with sub par results.
Have you tried to change the pivot of the camera? By parenting it to a empty object located at the same position of your "parent object".
Do you mean I should create an empty and attach the camera to that and then just rotate the empty? Sorry pretty tired atm
Are you just trying to get the camera to orbit around an object like in a typical 3rd person game? I would say make a copy of the mouse orbit script that comes with unity and try modifying that. If you don't want to write it in java which that script is written in then here is the core functionality of an orbit cam in c #
public Transform target;
Vector3 position;
Quaternion rotation;
float y;
float x;
public float distance = 5f;
public float xSpeed = 250.0f;
public float ySpeed = 120.0f;
public float y$$anonymous$$inLimit = -20f;
public float y$$anonymous$$axLimit = 80f;
Update(){
transform.position = position;
transform.rotation = rotation;
x += Input.GetAxis("$$anonymous$$ouse X") * xSpeed *1.5f*Time.deltaTime;
y -= Input.GetAxis("$$anonymous$$ouse Y") * ySpeed *1.5f*Time.deltaTime;
y = clampAxis(y, y$$anonymous$$inLimit, y$$anonymous$$axLimit);
rotation = Quaternion.Euler(y,x,0);
position = rotation * new Vector3(0,1,-distance) + target.position;
}
float clampAxis (float axis, float $$anonymous$$, float max){
if (axis < -360) {
axis += 360;
}
if (axis > 360) {
axis -= 360;
}
return $$anonymous$$athf.Clamp (axis, $$anonymous$$, max);
}
So it looks like you want to follow the contour of a box? Or do you just want to rotate in a half circle?
At first glance it looked like you wanted to make some weird camera for sitting behind cover, peeking up behind and at the sides of a wall, but that's not it, is it?
Your answer
Follow this Question
Related Questions
Lerp Not working 1 Answer
help with switching camera 0 Answers
Using DampSmooth in EulerAngle is affecting the Position.Z value of the gameObject. 0 Answers
Camera Roll/Headbob? 0 Answers