Hey there,
i would love my Camera to follow my Player even hes rotating etc … ,
thats what i would do via. global position,
then if i move the mouse, it should clamp the camera at the x/y coordinates “local position” at +66 / -66 degrees,
at the moment it work but not all,
if i follow my followObject via. script , it doesnt let me do my local movement , i hope you can follow me guys,
if not, feel free to write what you dont get im not native english speaker
Code:
void Update () {
//GETS CONTROLLER INPUT
float inputX = Input.GetAxis ("RightStickHorizontal");
float inputZ = Input.GetAxis ("RightStickVertical");
//MOUSE INPUT
mouseX = Input.GetAxis ("Mouse X");
mouseY = Input.GetAxis ("Mouse Y");
//CONTROLLER + MOUSE INPUT (IN CASE SOMEONE USES CONTROLLER)
finalInputX = inputX + mouseX;
finalInputZ = inputZ + mouseY;
//GETS THE Y AND X ROTATION TIMES THE SENSIVITY AND THE TIME(so it look good)
rotY += finalInputX * inputSensitivity * Time.deltaTime;
rotX += finalInputZ * inputSensitivity * Time.deltaTime;
//RETURNS X (Clamping Works also while turning)
rotX = Mathf.Clamp (rotX, -clampAngle, clampAngle);
//NOT WORKING
rotY = ClampAngle(rotY, -(CameraFollowObj.transform.position.y + clampAngle), CameraFollowObj.transform.position.y + clampAngle);
//Vector3 eulerRotation = new Vector3(transform.eulerAngles.x, CameraFollowObj.transform.eulerAngles.y, transform.eulerAngles.z);
Quaternion localRotation = Quaternion.Euler(rotX, rotY, 0.0f);
transform.rotation = localRotation;
}
void LateUpdate () {
CameraUpdater ();
}
void CameraUpdater() {
// set the target object to follow
Transform target = CameraFollowObj.transform;
//move towards the game object that is the target
float step = CameraMoveSpeed * Time.deltaTime;
transform.position = Vector3.MoveTowards (transform.position, target.position, step);
//Vector3 eulerRotation = new Vector3(transform.eulerAngles.x, CameraFollowObj.transform.eulerAngles.y, transform.eulerAngles.z);
Vector3 eulerRotation = new Vector3(transform.eulerAngles.x, CameraFollowObj.transform.eulerAngles.y, transform.eulerAngles.z);
transform.rotation = Quaternion.Euler(0 , eulerRotation.y, 0);
}
public float ClampAngle(float angle, float min, float max)
{
if (angle < -360F) { angle += 360F; }
if (angle > 360F) { angle -= 360F; }
return Mathf.Clamp(angle, min, max);
}
if i remove
Vector3 eulerRotation = new Vector3(transform.eulerAngles.x, CameraFollowObj.transform.eulerAngles.y, transform.eulerAngles.z);
transform.rotation = Quaternion.Euler(0 , eulerRotation.y, 0);
then it does work BUT only on “global axis” … and my camera doesnt follow my character anymore