- Home /
Question by
sebasrez · Apr 10, 2014 at 09:05 PM ·
axisrotate objectforward
Y forward on rotation not X
I found this script on the forums which works for what I need but it sets up the X to look at the object while I need -Y to look at the object.
Anyone know what set up I could use to change this??
private var mousePos : Vector2;
private var screenPos : Vector3;
function Update () {
mousePos = Input.mousePosition;
screenPos = Camera.main.ScreenToWorldPoint(Vector3(mousePos.x, mousePos.y, transform.position.z - Camera.main.transform.position.z));
transform.rotation.eulerAngles.z = Mathf.Atan2((screenPos.y - transform.position.y), (screenPos.x - transform.position.x))*Mathf.Rad2Deg;
}
rotation2.png
(30.1 kB)
Comment
Best Answer
Answer by robertbu · Apr 10, 2014 at 09:07 PM
Replace line 10 with:
var angle = Mathf.Atan2((screenPos.y - transform.position.y), (screenPos.x - transform.position.x))*Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis(angle + 90.0, Vector3.forward);
Thanks! this is it! I wish I had the 15 rep to thumbs up