当前位置: 首页 > ai >正文

Unity实现不倒翁

Unity实现不倒翁

Unity 实现不倒翁

不倒翁插件下载地址:
这是一个下载地址
https://www.aigei.com/item/zekpackage_unit.html
请使用URP渲染管线创建工程,导入此插件,有问题评论区告诉我。
备用下载地址:B站

using UnityEngine;[RequireComponent(typeof(Rigidbody))]
public class RolyPoly : MonoBehaviour
{[Header("重心设置")][Tooltip("重心高度偏移(负值降低重心)")]public float centerOfMassOffset = -0.25f;[Header("物理参数")][Range(0.1f, 10f)] public float angularDrag = 2f;[Range(0.1f, 10f)] public float maxAngularVelocity = 8f;private Rigidbody rb;private Vector3 originalCenterOfMass;[Header("摇摆优化")]public float stabilizationForce = 5f;/*  参数、作用、推荐值
centerOfMassOffset  重心越低越稳定	(-0.5,  -1.5)
angularDrag 旋转阻力,值越大停止越快	(1.0, 3.0)
maxAngularVelocity 最大旋转速度	(5, 10)
stabilizationForce 主动稳定力度	(2, 5)
*/void Start(){rb = GetComponent<Rigidbody>();rb.maxAngularVelocity = maxAngularVelocity;rb.angularDrag = angularDrag;// 设置重心originalCenterOfMass = rb.centerOfMass;AdjustCenterOfMass();}void AdjustCenterOfMass(){// 降低重心(Y轴负方向)Vector3 newCenter = originalCenterOfMass;newCenter.y += centerOfMassOffset;rb.centerOfMass = newCenter;}void FixedUpdate(){// 增加稳定性if (rb.velocity.magnitude < 0.1f){Vector3 uprightDirection = Vector3.up;Vector3 currentUp = transform.up;// 计算恢复力矩Vector3 torque = Vector3.Cross(currentUp, uprightDirection);rb.AddTorque(torque * stabilizationForce, ForceMode.Acceleration);}}// 可选:在编辑器中可视化重心void OnDrawGizmosSelected(){if (!Application.isPlaying) return;Gizmos.color = Color.red;Gizmos.DrawSphere(transform.TransformPoint(rb.centerOfMass), 0.1f);}
}
http://www.xdnf.cn/news/13158.html

相关文章:

  • Dispatch PDI(DPDI)kettle调度管理平台稳定版本,正式登场!
  • Nuxt + Pinia + Element Plus 后台管理系统搭建教程(含源码)
  • CMake测试find_package()命令的相关原理
  • 10- AI大模型-LangChainV0.3应用(一) - 简介,模型调用,prompt模板,输出解析器
  • 6.10
  • Vue.js 中的 v-bind 指令详解
  • Vue 模板语法之指令语法详解
  • 深入解析 GitHub Token 与 NPM Token:自动化发布的完整指南
  • 医学图像分割最新进展
  • 苹果签名应用掉签频繁原因排查,以及如何避免
  • WebRTC 中 ICE 流程优化:SRS 轻量级部署与 NAT 类型检测实战
  • 项目管理三要素有哪些?如何实现项目管理的三要素平衡
  • 题单:归并排序
  • DSP——时钟树讲解
  • 使用联邦学习进行CIFAR-10分类任务
  • 消防车辆管理系统:为消防公车筑牢安全与效率防线
  • 磐维数据库的权限使用
  • spark数据处理练习题番外篇【下】
  • 统计学核心概念与现实应用精解(偏机器学习)
  • ios 26官宣:car play升级提升车载体验
  • 丝杆升降机的物联网与大数据应用的具体例子
  • React 19 新特性
  • VSCode中PHP使用Xdebug
  • IP 地址查询在证券交易中的应用方式
  • spark数据处理练习题番外篇【上】
  • ffmpeg windows 32位编译
  • 如何安全地准备 iPhone 以旧换新(分步说明)
  • 深度解析qemu-guest-agent:架构原理、核心场景与部署实践
  • 【笔记】NVIDIA AI Workbench 安装记录
  • Docker加入用户组