【问题标题】:Why does my player's speed decreASE hugely on collision with this platform为什么我的播放器在与此平台碰撞时速度会大幅下降
【发布时间】:2020-08-08 10:19:26
【问题描述】:

在我的游戏中,我有从 a 点移动到 b 点的平台,当玩家出于某种原因降落在平台上时,他在平台上的速度会大大降低。

移动平台代码:

private void Start()
{
    isActive = true;
}

void Update()
{
    if (isActive == true)
    {
        transform.position = Vector3.Lerp(pos1, pos2, Mathf.PingPong(Time.time * speed, 1.0f));
    }

}`

玩家有代码使他在碰撞时成为平台的孩子,以确保它不会从平台上掉下来。 :

if(other.gameObject.CompareTag("MGround"))
{
     landEffect.Play();
     playerSpeed = 8;
     this.transform.parent = other.transform;
     isJumping = false;
}

任何帮助将不胜感激。

【问题讨论】:

  • 如果删除 playerSpeed = 8; 部分会怎样?
  • @MathewHD 我补充说以对抗减速:)
  • 为什么玩家不能从平台上掉下来?

标签: c# unity3d 2d


【解决方案1】:

如果你缓存你的玩家刚体的速度,如果他与平台发生碰撞,你可以解决这个问题,将刚体速度设置为缓存的值。 Rigidbody.velocity

// Put this somewhere in your Player script
private Vector3 tmpPlayerVelocity;
void LateUpdate() 
{
    tmpPlayerVelocity = yourPlayerRigidbody.velocity;
}

// Put this after your collision code
yourPlayerRigidbody.velocity = tmpPlayerVelocity;

【讨论】:

  • 好的,对不起,如果它适用于其他人,我会留下答案
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多