Question by
samccloy4 · Jul 07, 2021 at 05:50 AM ·
clamped rotation
Prevent Rotation on my aim
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ArmRotation : MonoBehaviour
{
public int rotationOffset = 90;
void Update () {
Vector3 difference = Camera.main.ScreenToWorldPoint (Input.mousePosition) - transform.position;
difference.Normalize ();
float rotZ = Mathf.Atan2 (difference.y, difference.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler (0f, 0f, rotZ + rotationOffset );
}
}
Comment
I want to stop my character from ai$$anonymous$$g past 180 degrees and bellow 0 degrees
You can use Mathf.Clamp
rotation = Mathf.Clamp(rotation, -clampupvalue, clampdownvalue);
Your answer
Follow this Question
Related Questions
How to clamp horizontal rotation of the camera? 1 Answer
Clamp a 2D object controlled by the mouse 0 Answers
Object Rotation With Touch 0 Answers
How do I clamp this camera rotation? 0 Answers