最近做的一个固定视角平台跳跃推箱子游戏中,主角的Z轴需要固定,勾选了刚体的Freeze Position Z之后,主角移动跳跃均正常,但与箱子发生碰撞时会出现抖动、偏移原有位置等问题。
解决方法:
- 确保刚体中需要的约束都已勾选上:
- 将刚体的质心设为0,惯性张量旋转设为单位四元数:
rigidbody.centerOfMass = Vector3.zero;
rigidbody.inertiaTensorRotation = Quaternion.identity;
- 对于无法推动的箱子,加入墙体检测,限制主角推动它们:
void GroundAndWallCheck()
{
...
isAgainstWall = false;
foreach (var item in wallCheckPoints)
{
cols = Physics.OverlapSphere(item.position, wallCheckRadius, wallLayer);
if (cols.Length != 0)
{
isAgainstWall = true;
break;
}
}
}
网友评论