Hi, I’m tring to make an animation in which enemy shoots player. Of course player will be moving on the map, so I can’t make static hand rotation in animation as I can’t access player position there.
When I change bone rotation in script (in event function called from animation / Update / LateUpdate), the rotation doesn’t apply, despite I’m not even changing that bone rotation in animation (I do change it’s position).
So is there any way to change that rotation outside animation? Or maybe there is a possibility to pass a parameter to animation that tells how much to rotate bone?
Also I’ve found this solution but it’s based on “animation” variable which if I understand correctly is GetComponent(). I’m using animator for animating characters so can I access the “animation” somehow?
using UnityEngine;
public class MyAnimationController : MonoBehaviour
{
[SerializeField] private Transform _rightHand;
[SerializeField] private Transform _leftHand;
private EnemyController _enemyController;
private Quaternion _leftHandRotation;
private Quaternion _rightHandRotation;
void Start()
{
_enemyController = GetComponentInParent<EnemyController>();
}
public void RightHandAimPlayer() // event called from animation
{
var vector = _enemyController.Player.transform.position - _rightHand.transform.position;
_rightHandRotation = Quaternion.LookRotation(vector, Vector3.back);
_rightHand.rotation = _rightHandRotation;
}
public void LeftHandAimPlayer() // event called from animation
{
var vector = _enemyController.Player.transform.position - _leftHand.transform.position;
_leftHandRotation = Quaternion.LookRotation(vector, Vector3.back);
_leftHand.rotation = _leftHandRotation;
}
private void LateUpdate()
{
_leftHand.rotation = _leftHandRotation;
_rightHand.rotation = _rightHandRotation;
}
}