I’m trying to make a good looking rotation, but here’s the problem, the rotation of my objects is stop after a couple of second and I don’t know why…
using UnityEngine;
public class Rotation : MonoBehaviour
{
public Transform[] anchorPoints;
private float rotationSpeed = 75f;
private GameObject gameNode;
private Quaternion RotationNode;
private bool canRotate = false;
private void Awake()
{
gameNode = GameObject.FindGameObjectWithTag("MovableGoal");
RotationNode = transform.rotation;
}
private void Update()
{
if (gameNode != null)
{
foreach (Transform anchor in anchorPoints)
{
if (anchor.position.x <= gameNode.transform.position.x - 0.05)
{
canRotate = true;
}
else if (anchor.position.y <= gameNode.transform.position.y - 0.05)
{
canRotate = true;
}
else
{
canRotate = false;
}
}
if (canRotate)
{
RotateGameNodes(gameNode);
}
}
else
{
transform.rotation = RotationNode;
}
}
private void RotateGameNodes(GameObject gameNode)
{
transform.Rotate(transform.rotation.x, transform.rotation.y, -rotationSpeed * Time.deltaTime);
gameNode.transform.RotateAround(transform.position, -transform.forward, rotationSpeed * Time.deltaTime);
}
}