The parent acts like an anchor for the childen to rotate arround, if i change the Z rotation in the editor, it turn over the anchor
but when i try to rotate it using a script (sawHolder (img2) contains the script )
the saw rotate over self and i don’t know how to make it rotate over the parent in the script, would apreciate any help, thanks!
My Script:
public class rotationSaw : MonoBehaviour {
private void LateUpdate()
{
transform.Rotate(new Vector3(0,0,1));
}
}
I would guess that you have the script on the saw as well.
However, I put this together quickly for someone on reddit the other day which gives you a few options if you want to use it instead. Make sure it is only on the parent object.
using UnityEngine;
public class RotateObject : MonoBehaviour
{
public enum RotationAxis
{
XAxisClockwise,
XAxisAntiClockwise,
YAxisClockwise,
YAxisAntiClockwise,
ZAxisClockwise,
ZAxisAntiClockwise
}
public RotationAxis rotationAxis;
public float RotationSpeed;
public int RotationCount = 0;
[Tooltip("Set to 0 for infinite Roatations")]
public int MaxRotations = 2;
public bool Rotate = false;
private float Rotations;
private Vector3 RotationDirection;
private void Start()
{
StartRotating();
}
private void Update()
{
if (Rotate)
{
transform.Rotate(RotationDirection * RotationSpeed * Time.deltaTime);
Rotations += RotationSpeed * Time.deltaTime;
RotationCount = (int)Rotations / 360;
if(MaxRotations > 0 && RotationCount >= MaxRotations)
{
Rotate = false;
}
}
}
private void StartRotating()
{
switch (rotationAxis)
{
case RotationAxis.XAxisClockwise:
RotationDirection = Vector3.right;
break;
case RotationAxis.XAxisAntiClockwise:
RotationDirection = Vector3.left;
break;
case RotationAxis.YAxisClockwise:
RotationDirection = Vector3.up;
break;
case RotationAxis.YAxisAntiClockwise:
RotationDirection = Vector3.down;
break;
case RotationAxis.ZAxisClockwise:
RotationDirection = Vector3.back;
break;
case RotationAxis.ZAxisAntiClockwise:
RotationDirection = Vector3.forward;
break;
default:
RotationDirection = Vector3.right;
break;
}
Rotations = 0;
Rotate = true;
}
}