简体   繁体   English

unity Rigidbody 有速度但不移动

[英]Unity Rigidbody has velocity but not moving

I have a game in Unity where cubes are repeatedly moved past the camera.我在 Unity 中有一个游戏,其中立方体反复移动经过相机。 I move the cube using a script where I set its Rigidbody's velocity each update.我使用脚本移动立方体,在其中设置其 Rigidbody 每次更新的速度。 Once it moves out of view my script instantiates a new cube on the other side which begins the process again.一旦它移出视野,我的脚本会在另一侧实例化一个新的立方体,再次开始该过程。 Recently I've found that it works fine for a random amount of cubes before, seemingly randomly, a cube is instantiated that does not move.最近我发现它在随机数量的立方体之前工作正常,看似随机,一个立方体被实例化而不移动。 Using the inspector I can see that this object has velocity.使用检查器我可以看到这个对象有速度。 If I move it even a small amount using the editor it starts to move as normal.如果我使用编辑器稍微移动它,它就会开始正常移动。 Has anyone seen something like this before?有没有人见过这样的东西?

May be you are changing the velocity of your gameObject when it goes through a specific coordinate (in an if statement for example), unity is not very accurate sometimes with coordinates so it may be happening that the condition is never met.可能是当您的游戏对象通过特定坐标时(例如在 if 语句中),您正在改变它的速度,有时坐标的统一性不是很准确,因此可能会发生从未满足条件的情况。 Change that condition and add a margin range to solve this error.更改该条件并添加边距范围以解决此错误。

I'm fairly certain the problem was related to the fact I was trying to directly modify the velocity( The physics engine decided the object was at rest and stopped it moving. ).我相当肯定这个问题与我试图直接修改速度的事实有关(物理引擎决定对象处于静止状态并停止移动。)。 By setting the object to be kinematic and modifying its position in my code I solved the problem.通过将对象设置为运动学并修改它在我的代码中的位置,我解决了这个问题。

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

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