kingBook

导航

Unity 旋转欧拉角X时,重力加速度模拟


如图,要求角色捉住杆不停旋转,当旋转至脚朝上时,受到重力速度要求逐渐减速旋转,反之加速旋转。

// 125f 为没有重力时旋转速度
float angleVelocity=125f;
// 加重力
// ((transform.up.y+1f)/2f) 范围区间[0,1]脚朝上最小,脚朝下最大;
// 300f 为重力大小
angleVelocity+=((transform.up.y+1f)/2f) * 300f;

angleVelocity*=Time.deltaTime;

// 围绕旋转的点
// m_bodyExtents.y 为身体高度的一半
Vector3 aroundPoint=transform.position+transform.up*m_bodyExtents.y;
transform.RotateAround(aroundPoint,transform.right,angleVelocity);

posted on 2021-04-01 16:21  kingBook  阅读(192)  评论(0编辑  收藏  举报