- Home /
Question by
Lastonestanding · May 21 at 02:11 PM ·
c#camera rotaterts
How to I get the Camera to Smooth Transition between to set Values for the X Axis
Ok I am making a Camera that can zoom in and out (A RTS Camera) but I was wanting to get the Camera's Angle to change as it Zooms in and out. I figured out I have to use the transform.eulerAngles to get that effect. But it snaps to those positions when I reach the max Height and Lowest Height and dose not transition smoothly between the two. I am not sure how to approach this when writing the code. Here is what I have done so far and Pictures are to show what I am trying to aim for:
public class CameraMovement : MonoBehaviour
{
float speed = 0.06f;
float zoomSpeed = 10.0f;
float rotateSpeed = 0.1f;
float maxHeight = 65f;
float minHeight = 3f;
float XposHH = 50f;
float XposHL = 3f;
Vector2 p1;
Vector2 p2;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.LeftShift))
{
speed = 0.06f;
zoomSpeed = 20.0f;
}
else
{
speed = 0.035f;
zoomSpeed = 10.0f;
}
float hsp = transform.position.y * speed * Input.GetAxis("Horizontal");
float vsp = transform.position.y * speed * Input.GetAxis("Vertical");
float scrollSp = -zoomSpeed * Input.GetAxis("Mouse ScrollWheel");
if (((transform.position.y >= maxHeight)) && (scrollSp > 0))
{
scrollSp = 0;
transform.eulerAngles = new Vector3(XposHH, 0, 0);
}
else if ((transform.position.y <= minHeight) && (scrollSp < 0))
{
scrollSp = 0;
transform.eulerAngles = new Vector3(XposHL, 0, 0);
}
Zoomed Out https://ibb.co/q0VDLBM
Zoomed In: https://ibb.co/581Kd3C
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
constructing buildings rts style. 1 Answer
Lean/Peak system 1 Answer
rts developement 0 Answers