Setting transform.eulerAngles doesn't work in a StateMachineBehaviour script
I'm trying to create an attack for boss fight where a projectile spins progressively faster around the player's position before settling on a random rotation and directly targeting the player. As of this moment the only part of the attack I've implemented is the spinning. However, while it is moving around the player correctly, it is not rotating to point towards them. Here's my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FBHCircle : StateMachineBehaviour
{
private float rotationValue;
[SerializeField] private float maxSpeed;
private float currentSpeed;
[SerializeField] private float radius;
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
rotationValue = 0;
}
// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
currentSpeed = maxSpeed * 4 * stateInfo.normalizedTime * (1 - stateInfo.normalizedTime);
rotationValue += currentSpeed * Time.deltaTime;
animator.transform.position = GameObject.Find("Player").transform.position + (radius * new Vector3(Mathf.Sin(rotationValue), Mathf.Cos(rotationValue)));
animator.transform.eulerAngles = Vector3.forward * rotationValue;
}
}
Right now, setting animator.transform.position is giving me no problems and it is working as expected, but trying to rotate the object by setting animator.transform.eulerAngles just doesn't do anything. The projectile's rotation is not being set within the actual animation, so something else must be overriding it but I have no idea what. This is the second time I've tried to rotate an object within a StateMachineBehaviour script and it has worked neither time. I've also tried several different solutions other than setting transform.eulerAngles, including setting transform.rotation, using transform.Rotate(), and transform.LookAt(), none of which have worked either. I'm getting a little desperate as I've already posted the question on StackOverflow and gotten nothing useful out of it and I have a bit of a tight deadline, so any help with the issue would be greatly appreciated.