Aim boxing (AimIK)

AimIK有利于物体稳定地瞄准目标。有时这些对象在动画中有很多摆动动作,比如挥剑,使用AimIK在摆动过程中将剑保持朝向某个位置是不好的。

它将通过弯曲脊椎层次结构的其余部分来固定剑的方向,并且以不自然的方式干扰动画。

仍然可以使用AimIK来重定向摇摆动画,如剑术或拳击。为此,我们必须告诉AimIK每帧无论当前动画姿态是什么,它都是默认的前向瞄准姿态。

这可以通过在AimIK解决之前将AimIK的aim Tranform朝向目标旋转或通过调整AimIK轴(Aixs)来实现。

在这里插入图片描述
在这里插入图片描述

并在打击目标球上加Aim Boxing脚本

namespace RootMotion.Demos {

    /// <summary>
    /// Boxing with Aim IK.
    /// AIM拳击
    /// Changing character facing direction with Aim IK to follow the target.
    /// 改变角色面对方向相对于AIM IK跟随的目标
    /// </summary>
    public class AimBoxing : MonoBehaviour {

		public AimIK aimIK; 
        // Reference to the AimIK component
        //引用AIMIK组件
		public Transform pin;
        // The hitting point as in the animation
        //动画中的击球点

        void LateUpdate() {
            // Rotate the aim Transform to look at the point, where the fist hits it's target in the animation.
            //旋转aim Transform以查看点,拳头在动画中击中目标。
            // This will set the animated hit direction as the default starting point for Aim IK (direction for which Aim IK has to do nothing).
            //这将将动画命中方向设置为AIM IK的默认起始点(AIM IK没有默认方向)。
            aimIK.solver.transform.LookAt(pin.position);

            //LookAT :旋转物体使z轴指向目标物体
            //当人物 AIM IK 设置了LookAt并指定了目标物体(pin.position)时,该物体的z轴将始终指向目标物体 是世界坐标

            // Set myself as IK target
            //把自己设定为IK目标
            aimIK.solver.IKPosition = transform.position;
		}
	}
} 

效果如下:
在这里插入图片描述

Aim Transform -你想要瞄准目标的Transform ,必须成为骨骼等级(层次)权重的直系后代,举个例子,如果你想瞄准一把枪,就把枪放入Aim Transform,或是Aim Transform 的子物体或者是手的骨骼

猜你喜欢

转载自blog.csdn.net/qq_42782299/article/details/84447805