- Home /
object is not rotating from right direction
hi there, im beginner to unity so im using this code to rotate object with mouse with max rotation of 35 degrees,it is working but it's only possible to rotate object if mouse is under of that object. here is my code: using System.Collections; using System.Collections.Generic; using UnityEngine;
public class rotObj : MonoBehaviour {
//private float baseAngle = 0.0f;
private float maxRotaion = 35f;
void Update () {
var dir = Camera.main.ScreenToWorldPoint (Input.mousePosition) - transform.position;
var angle = Mathf.Atan2 (dir.y, dir.x) * Mathf.Rad2Deg;
if (angle >= -maxRotaion && angle <= maxRotaion)
transform.localRotation = Quaternion.AngleAxis (angle, Vector3.forward);
}
}
as i think, localrotation is making that problem? how can i fix this without removing maximum rotation angle and will be able to rotate object not just from mouse under object, but from any position? my english grammar is very bad but i hope you will understand
Your answer
Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
Rotation from AngleAxis() ToAngleAxis() flips back and forth 1 Answer
reproducing hingejoint.angle 0 Answers
Location in relation to other objects rotation 1 Answer
Change the roll of the rotation 0 Answers