- Home /
Question by
KloverGames · Jul 30, 2019 at 05:17 PM ·
rotationquaterniontransform.rotationmathf.clamp
How to make a gameobject have a rotation constraint?
I'm looking for how to get my player object to rotate but not past 45 degrees and -45 degrees, I sorta got this to work before but after rotating to one of the constraints, it wouldn't allow me to rotate back.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class RotateTestScript : MonoBehaviour {
// Update is called once per frame
void Update()
{
if (Input.GetKey("a"))
{
transform.Rotate(-Vector3.forward * 15f);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
I'm having trouble clamping the rotation of the camera? 0 Answers
How can I align axis with quaternion.fromToRotation? 1 Answer
How to combine multiple rotations at once? 0 Answers
Limit Rotation of Camera around a player using keyboard 1 Answer
Follow rotation on Y axis ONLY clockwise/counterclockwise. 1 Answer