(一)铰链组件
1.创建一个立方体和角色胶囊
2.给角色胶囊挂在控制脚本和刚体
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class plyer : MonoBehaviour
{// Start is called once before the first execution of Update after the MonoBehaviour is createdvoid Start(){}// Update is called once per framevoid Update(){// 水平轴float horizontal = Input.GetAxis("Horizontal");// 垂直轴float vertical = Input.GetAxis("Vertical");// 向量Vector3 dir = new Vector3(horizontal, 0, vertical);// 朝向范方向移动transform.Translate(dir * 2 * Time.deltaTime);}
}
4.给立方体挂载刚体Rigidbody和铰链Hinge Joint组件
效果
untiy 3d 弹簧组件
(二)弹簧组件
1.创建2个立方体
2.给2个立方体挂在刚体组件
3.给上面的立方体挂在弹簧组件并给上面的立方体设置是运动学防止掉下来
运行效果
untiy 3d 弹簧组件