简体   繁体   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 with anything around to turn the 'isJumping' bool false, making the character idle again. 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'布尔值变为假,使角色再次空闲。 However, I noticed that there would be this glitch where the character's walking animations would loop when landed.但是,我注意到在着陆时角色的行走动画会循环出现这种故障。 I later saw that the BoxCollider did not move upwards with the character, therefore making every collision based event impossible to trigger.后来我看到 BoxCollider 没有随着角色向上移动,因此使得每个基于碰撞的事件都无法触发。

I initially tried to tie the BoxCollider with.AddForce (Player.BoxCollider.AddForce()), but to no avail.我最初尝试将 BoxCollider 与.AddForce (Player.BoxCollider.AddForce()) 绑定,但无济于事。 I also tried to turn off the BoxCollider and turn it back on again, but that method also didn't work.我还尝试关闭 BoxCollider 并重新打开它,但该方法也不起作用。

Here's the code for the Jumping command:这是跳跃命令的代码:

    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);
    }

And this is the code for any kind of collisions:这是任何类型的碰撞的代码:

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

I expect the isJumping trigger to be considered false.我希望 isJumping 触发器被认为是错误的。

Your player will eventually come down because it has rigidbody component attached to it, you don't need to addforce to comes it down你的播放器最终会掉下来,因为它附有刚体组件,你不需要加力让它掉下来

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

相关问题 Rigidbody.AddForce() 对象旋转后不起作用 - Rigidbody.AddForce() not working after object is rotated 如何修复 Unity Rigidbody.AddForce 问题? - How to fix Unity Rigidbody.AddForce problem? unity 3d:刚体.AddForce(forceDirection.normalized *力)将对象移离父级和关节 - unity 3d: rigidbody.AddForce(forceDirection.normalized * force) moving objects away from parent and joint 我可以在不漂移的情况下使用 RigidBody.Addforce 吗? - Can I use RigidBody.Addforce without drifting? “oncollisionenter”中的 Rigidbody.Addforce 未在统一 c# 中执行 - Rigidbody.Addforce in"oncollisionenter" is not executing in unity c# Unity C#-Rigidbody.AddForce无法按预期工作 - Unity C# - Rigidbody.AddForce not working as intended 刚体.AddForce影响具有相同脚本组件的所有游戏对象 - rigidbody.AddForce affects all game objects with the same script component 您是否需要Rigidbody.addforce中的time.deltatime? - Do you need time.deltatime in Rigidbody.addforce? 向不起作用的刚体施加力。 错误:UnityEngine.Component不包含AddForce的定义,也不包含AddForce的扩展方法 - Adding force to a rigidbody not working. Error: UnityEngine.Component does not contain a definition for AddForce and no extension method for AddForce 刚体.AddForce()不要让我的玩家每次都以相同的高度跳跃 - rigidbody.AddForce() don't make my player jump at the same height everytime in unity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM