Question by
gosolo2 · Oct 01, 2017 at 11:21 PM ·
objectanglerotation axislimit
How to make the object return to its last angle (before the angle limit) go back no so abruptly ?
This code works fine but after the object in its rotation reach its angle limit the object abruptly goes back at the angle it was before it was limited. How to make the object or stopping rotating after reach the angle limit or go back to its last angle before it was limited but in a smooth rotation movement. Thanks
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class angleLimiter : MonoBehaviour {
public float minRotation = -45;
public float maxRotation = 45;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Vector3 currentRotation = transform.localRotation.eulerAngles;
currentRotation.x = Mathf.Clamp(currentRotation.x, minRotation, maxRotation);
transform.localRotation = Quaternion.Euler(currentRotation);
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612140103im_/https://answers.unity.com/themes/thub/images/avi.jpg)