如何解决Unity3D-在移动平台上检测碰撞
我正在尝试创建一个移动平台,该平台移动与其相连的物体,但也允许连接的物体检测高速碰撞。
我首先尝试使用transform.Translate()
移动对象,但这不支持那些高速碰撞。
注意:我已将所有脚本示例连接到红色立方体下方的平台。
public Transform connectedTo; // The red cube in the gif
private Vector3 lastPosition;
void FixedUpdate() {
// Calculate how much the vector has changed
Vector3 amountChanged = transform.position - lastPosition;
// Apply the amount changed to the connected object
connectedTo.transform.position += amountChanged;
// Update the last position
lastPosition = transform.position;
}
然后我尝试使用Rigidbody.Movetowards(destination);
代替,但这产生了相同的结果:
public Transform connectedTo; // The red cube in the gif
private Vector3 lastPosition;
void FixedUpdate() {
// Calculate how much the vector has changed
Vector3 amountChanged = transform.position - lastPosition;
// Get the point in which the object must move to
Vector3 destination = connectedTo.transform.position + amountChanged;
// Apply the amount changed to the connected object
connectedTo.GetComponent<Rigidbody>().Movetowards(destination);
// Update the last position
lastPosition = transform.position;
}
这是我在红色立方体上设置的刚体:
墙壁和平台都有一个标准的盒子对撞机。
我已阅读到要检测这些高速碰撞,必须启用连续碰撞检测,并且必须使用力进行移动。 Unity Documentation和High Speed Collision Video
强制问题是我不知道如何像以前的脚本那样使用平移来移动连接的对象。
// This barely moves the object connected to the platform
connectedTo.GetComponent<Rigidbody>().AddForce(amountChanged,ForceMode.Impulse);
使用固定关节将不允许连接的对象独立移动。
TL; DR:
我如何创建一个移动平台,以使顶部的事物随其移动,同时还能够独立移动并高速检测碰撞?
解决方法
setTimeout(() => {
history.push('xxx');
},100);
此代码位于Platform.Platform上,并具有作为触发器的额外Collider。 当玩家在扳机区域内时,他的速度会被直接修改,并且可以改变其速度,而不会成为动态刚体。 平台在旋转和垂直轴上也有限制。
,翻译使您可以观察到穿过墙壁的“传送”。如果速度足够快或FPS足够低,它将穿过墙壁。
选项:
- 使用Raycast保护翻译。从旧到新。
- 使用Spherecast或Boxcast来保护翻译
- 将平台+播放器输入的速度(这样您仍然可以行走)应用于播放器。
还请检查碰撞检测设置:
但是请注意,使用鼠标在场景中移动对象不会设置刚体的速度。因此,要测试它是否没有穿过墙,您需要使用物理学对平台进行乒乓球训练。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。