Later also to the sides but for now on Y.
using UnityEngine;
using System;
using System.Collections;
public class RotationTest : MonoBehaviour
{
public Transform target;
public Transform objToRotate;
void LateUpdate()
{
Vector3 relativePos = target.position - objToRotate.position;
Quaternion rotation = Quaternion.LookRotation(relativePos, Vector3.up);
rotation.y = Mathf.Clamp(rotation.y, -1f, 1f);
objToRotate.rotation = rotation;
}
}
I tried with the line :
rotation.y = Mathf.Clamp(rotation.y, -1f, 1f);
but it's not working I tried also the values -50f and 50f