Hi everyone, this is my script :
function Update () {
var hit : RaycastHit;
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, hit) && !Input.GetMouseButton(1) && !Input.GetMouseButton(2) && hit.rigidbody && PartPlacement.gui == false) {
transform.position = hit.point;
transform.rotation = Quaternion.LookRotation(hit.normal);
}
transform.eulerAngles.z = PartPlacement.rotation;
}
I am trying to make a rotation offset for Quaternion.LookRotation using eulerAngles. The code that I have so far does its job perfectly until the transform is aligned with y axes. Then instead of being an offset static float “rotation” becomes a rotation speed value or in other words instead of degrees it becomes revolutions per second. I need Quaternion.LookRotation to stay in the script if possible.
It’s fixed!
Full code:
function Update () {
var hit : RaycastHit;
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, hit)) {
transform.position = hit.point;
transform.rotation = Quaternion.LookRotation(hit.normal) * Quaternion.Euler(0, 0, PartPlacement.rotation);
}
}