I’m making a minigolf game (basically an advanced version of the rolling ball tutorial) and I’m trying to make a loading animation on the ball to indicate the force applied.
I use the following setup in the editor, with a canvas in worldspace attached to my ball prefab :
I also have the following script attached, to ignore the rotation of the parent in the canvas :
using UnityEngine;
public class UISliderRotation : MonoBehaviour
{
// Manipulate canvas rotation for slider elements on the ball so that it doesnt swing around
private Quaternion m_CanvasRotation;
private void Start()
{
// Local rotation at init
m_CanvasRotation = transform.localRotation;
}
public void SetRotation(Quaternion newRotation)
{
m_CanvasRotation = newRotation;
}
private void Update()
{
transform.rotation = m_CanvasRotation;
}
}
But when the ball is rolling, the canvas is spinning around the ball in a circular motion :
Is it expected behavior and how can I have the canvas stay in place while the ball is rolling? Should I use a canvas in screen space with WorldToScreenPoint instead ? I’m looking for something that matches what is in the first pic.
Thanks in advance.