我有一个2D平台,每个平台都有一个PlatformEffector2D
组件。 我想创造一个可以推动的箱子。
当我跳进箱子的边缘时,我的播放器卡住了,所以我将PlatformEffector2D
添加到箱子中。 但是当箱子有一个PlatformEffector2D
组件时,它就落在平台下面。
我可以删除组件,并添加一个零摩擦Physics2D
材料,以防止玩家卡在箱子的边缘,但我不能走在箱子上面(因为零摩擦)。 下面的图片说明了这一点。
玩家陷入没有PlatformEffector2D
的板条边缘。
如果它有一个PlatformEffector2D
它将落在平台下面。
我的物品有以下组件(当玩家被卡在一个箱子的边缘时):
Player (BoxCollider2D, Rigidbody2D)
Crate (BoxCollider2D, Rigidbody2D)
Platform (EdgeCollider2D, PlatformEffector2D)
我该怎么做,我的球员可以推箱子,并在箱子上面行走? 有人会碰巧有一个示例脚本?
FYI:我使用Physics2D.OverlapCircle来检测地面。 (Unity 5.4.0)
最后我修好了。 我添加了两个空的GameObject
来检查玩家的左侧和右侧。 现在他可以推箱子,在箱子上面行走而不会卡在箱子的边缘。
// Check if player is on the ground or not grounded = Physics2D.OverlapCircle (groundCheck.position, groundRadius, whatIsGround); rightSided = Physics2D.OverlapCircle (rightSideCheck.position, groundRadius, whatIsGround); leftSided = Physics2D.OverlapCircle (leftSideCheck.position, groundRadius, whatIsGround); // Movement if (!grounded && (rightSided || leftSided)) { // Do nothing } else { // Handle movement input }