[英]Player stuck in platform only when it moves
I'm working on a 3D platformer game, my player has a rigidbody attached to it, and I use rb.MovePosition() for movement.我正在开发一款 3D 平台游戏,我的播放器附有一个刚体,我使用 rb.MovePosition() 进行移动。
My platform has only a box collider.我的平台只有一个盒子对撞机。
I use the standard parenting method to make my player stay on the platform:我使用标准的育儿方法让我的玩家留在平台上:
protected virtual void OnCollisionEnter(Collision other)
{
if(isPlayerTag(other.gameObject.tag))
{
other.transform.parent = transform;
}
}
protected virtual void OnCollisionExit(Collision other)
{
if(isPlayerTag(other.gameObject.tag))
{
other.transform.parent = null;
}
}
Here's my issue: when the platform doesn't move, my player can freely move on the platform, but as soon as the platform moves, my player is stuck on it until the platform stops.这是我的问题:当平台不动时,我的播放器可以在平台上自由移动,但是一旦平台移动,我的播放器就会卡在上面直到平台停止。
I use FixedUpdate() for both movement.我对这两种运动都使用 FixedUpdate()。
For the platform:对于平台:
protected IEnumerator PlatformTranslation()
{
float movementPercent = 0f;
while(movementPercent < 1)
{
movementPercent += Time.fixedDeltaTime * platformSpeed;
transform.position = Vector3.Lerp(startingPosition, nextPositions,movementPercent);
yield return new WaitForEndOfFrame();
}
}
I've found a solution: I just had to switch the interpolate state of the rigidbody from none to interpolate.我找到了一个解决方案:我只需要将刚体的插值 state 从无切换到插值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.