Question by
CyberModeSoftware · Dec 29, 2020 at 10:14 PM ·
camera rotaterotatearound
Limit Rotate Around axis
I have big problems with limit axis on camera orbit with rotate around . What is happening?
public float minimumX = -90F;
public float maximumX = 90F;
public float minimumY = -60F;
public float maximumY = 60F;
float rotationY = 0F;
float rotationX = 0f;
public GameObject cameraTarget1;
public GameObject cameraTarget2;
public GameObject cameraTarget3;
public GameObject cameraTarget4;
public bool cam2 = false;
public float speed = 20f;
public Vector3 dist;
public Transform LookTarget;
public Transform fpTarget;
public Speedometer spedometer;
public Shifter shift;
public MoveCamera cameramove;
private int currenttarget;
private Transform cameratarget;
public GameObject ScreenDash;
public GameObject InteriorDash;
public GameObject Character;
public GameObject RearCamScreen;
public GameObject ScreenNavi;
public void Start()
{
currenttarget = 1;
SetCameraTarget(currenttarget);
}
public void LateUpdate()
{
Vector3 dPos = cameratarget.position + dist;
Vector3 sPos = Vector3.Lerp(transform.position, dPos, speed );
transform.position = sPos;
transform.LookAt(LookTarget);
if (Input.GetMouseButton(0))
{
cameraTarget1.transform.RotateAround(LookTarget.transform.position, Vector3.up, rotationX);
}
if (cam2 == true)
{
transform.LookAt(fpTarget);
}
else if (cam2 == false)
{
transform.LookAt(LookTarget);
}
}
public void SetCameraTarget(int num)
{
switch (num)
{
case 1:
cameratarget = cameraTarget1.transform;
cam2 = false;
ScreenDash.SetActive(enabled);
InteriorDash.SetActive(false);
Character.SetActive(true);
break;
case 2:
cameratarget = cameraTarget2.transform;
cam2 = true;
ScreenDash.SetActive(false);
InteriorDash.SetActive(enabled);
Character.SetActive(false);
break;
case 3:
cameratarget = cameraTarget3.transform;
cam2 = false;
ScreenDash.SetActive(enabled);
InteriorDash.SetActive(false);
Character.SetActive(true);
break;
case 4:
cameratarget = cameraTarget4.transform;
InteriorDash.SetActive(false);
cam2 = false;
Character.SetActive(true);
break;
}
}
private void RearScreenCam()
{
if (shift.reverse == true && cam2 == false)
{
ScreenNavi.SetActive(true);
RearCamScreen.SetActive(true);
}
else if (shift.reverse == false && cam2 == false)
{
RearCamScreen.SetActive(false);
ScreenNavi.SetActive(false);
}
}
public void SwitchCamera()
{
if (currenttarget < 4)
{
currenttarget++;
}
else
currenttarget = 1;
SetCameraTarget(currenttarget);
}
private void FixedUpdate()
{
RearScreenCam();
}
void Update()
{
rotationX = Input.GetAxis("Mouse X");
rotationX = Mathf.Clamp(rotationX,0,100);
}
Comment
Your answer
Follow this Question
Related Questions
Rotate camera around pivot not working on certain angles 0 Answers
Rotating Camera around Player's X-axis while rotating Player around its Y-axis (using mouse input) 0 Answers
How to use RotateAround with swipe gesture 0 Answers
Rotate Ball specific number of degrees and back again 0 Answers
How can I find the angle an object needs to turn towards a target from a rotated perspective? 0 Answers