繁体   English   中英

向角色的刚体 (rigidbody.AddForce) 添加力时,属性“BoxCollider”不会移动

[英]Property 'BoxCollider' does not move when force is added to character's rigidbody (rigidbody.AddForce)

I was trying to add a jump function into the game by having the character have a jumping animation and use the 'rigidbody.AddForce' function to actually make it jump.For the character to return back to its idle position, it would need to collide有任何东西可以将'isJumping'布尔值变为假,使角色再次空闲。 但是,我注意到在着陆时角色的行走动画会循环出现这种故障。 后来我看到 BoxCollider 没有随着角色向上移动,因此使得每个基于碰撞的事件都无法触发。

我最初尝试将 BoxCollider 与.AddForce (Player.BoxCollider.AddForce()) 绑定,但无济于事。 我还尝试关闭 BoxCollider 并重新打开它,但该方法也不起作用。

这是跳跃命令的代码:

    if (Input.GetKeyDown(KeyCode.Space) && isJumping == false)
    {
        isJumping = true;
        thePlayer.GetComponent<Animator>().Play("Jump");
        rb.AddForce(new Vector3(0, 4, 0), ForceMode.Impulse);
        rb.AddForce(new Vector3(0, -4, 0), ForceMode.Impulse);
    }

这是任何类型的碰撞的代码:

   void OnCollisionEnter(Collision col)
{
    isJumping = false;
}

我希望 isJumping 触发器被认为是错误的。

你的播放器最终会掉下来,因为它附有刚体组件,你不需要加力让它掉下来

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM