Hello!
I’m still pretty new to coding, and I haven’t seemed to come up with a solution to this little problem I have. Its a cannon that rotates up and down to
I want to clamp a rotation on one axis for a 2D game so that its not able to spin all the way round.
void Update () {
if (angleUp)
{
transform.Rotate(0, 0, -speed);
}
if (angleDown)
{
transform.Rotate(0, 0, speed);
}
I’ve tried clamping the rotation using transform.rotation.z = Mathf.Clamp(transform.rotation.z, x,y)
But I get an error “Cannot modify the return value of ‘Transform.rotation’ because it is not a variable”
and I’ve tried clamping the euler angles, which has just stopped the rotation entirely?
There doesn’t seem to be a quick solution to this issue?