首先找到人物胸部的顶点骨骼位置,拷贝一下
如图所示
然后在原物体上挂栽如下脚本
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Wobbler : MonoBehaviour {
/// <summary>
/// 中心点的位置(拉入拷贝后的物体)
/// </summary>
public Transform centerTran;
/// <summary>
/// 我的位置
/// </summary>
Transform myTransform;
/// <summary>
/// 刚体组件
/// </summary>
Rigidbody rig;
/// <summary>
/// 弹性系数
/// </summary>
public float hardness;
private void Start()
{
//Time.timeScale = 0.1f;
rig = GetComponent<Rigidbody>();
myTransform = transform;
}
private void FixedUpdate()
{
//防止动作大的时候摆动穿模
if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.