In my game I have a player controller space ship, and I have game objects attached to the ship which instantiate weapon bolts when the player fires. I need these objects to not rotate along the X axis when the player tilts from left to right, but my script isnt working (i’m probably not doing it right…)
This is what I have:
public class NoRotate : MonoBehaviour
{
[SerializeField]
private bool isXLocked = true;
[SerializeField]
private bool isYLocked = false;
[SerializeField]
private Transform Target;
void Update()
{
float xTarget = Target.rotation.x;
float yTarget = Target.rotation.y;
float xNew = transform.rotation.x;
if (!isXLocked)
{
xNew = Mathf.Lerp(transform.rotation.x, xTarget, Time.deltaTime);
}
float yNew = transform.rotation.y;
if (!isYLocked)
{
yNew = Mathf.Lerp(transform.rotation.y, yTarget, Time.deltaTime);
}
}
}
Any clues as to what I can do to make it work?