using System.Collections; using System.Collections.Generic; using UnityEngine; public class ArmorSoldierScript : MonoBehaviour { // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { } private void OnAnimatorMove() { Animator animator = GetComponent(); // animator.deltaPosition和animator.deltaRotation是animator做的root motion后的结果 // 在后面做一个硬性约束z=0,将角色限制在z=0平面上 if (animator) { Vector3 position = transform.position; position.x += animator.deltaPosition.x; position.y += animator.deltaPosition.y; transform.position = position; // animation clip导入设置旋转一般上设置为baked inpose,不需要手动限制 transform.rotation *= animator.deltaRotation; } } }