简体   繁体   English

如何使用 Cannon.js + Three.js 让对象跳跃

[英]How can i make an object jump using Cannon.js + Three.js

While searching for this solution, I noticed many used, cannonBody.velocity.y = JUMP_VELOCITY在寻找这个解决方案时,我注意到很多使用, cannonBody.velocity.y = JUMP_VELOCITY

But in my case, It works while the object is already in motion but not once it became stationary.但就我而言,它在物体已经在运动时起作用,但在物体静止时不起作用。 So, I was wondering if there are a few conditions to be met for it to jump.所以,我想知道它是否需要满足一些条件才能跳转。

I would also encourage a demo snippet of making a simple object (a ball) to jump when the spacebar is pressed.我还鼓励制作一个简单的对象(一个球)在按下空格键时跳跃的演示片段。

I switched to OimoPhysics and things woke up properly.我切换到 OimoPhysics 并且一切正常。 It uses the same conventions.它使用相同的约定。 How it replaces the physics world in a declarative setup, I don't know..?它如何在声明式设置中取代物理世界,我不知道..? I've done that with Canon, where you set the config tolerance.我已经用佳能做到了,您可以在其中设置配置容差。 But even with the quick setup where you just add a body or move it, Oimo solved the sleep problem immediately.但是,即使您只需添加一个身体或移动它的快速设置,Oimo 立即解决了睡眠问题。 ApplyForce would be more consistent and realistic than an arbitrary + y value. ApplyForce 将比任意 + y 值更一致和更现实。 I think applyForce would give less problems.我认为 applyForce 会减少问题。

It's easy to forget to call update on the physics after you move the geometry.移动几何体后很容易忘记调用物理更新。 If the render loop misses a step your geometry may be frozen, lost to the physics body.如果渲染循环错过了一个步骤,您的几何体可能会被冻结,丢失到物理体中。 Or if you add another physics body in its place the original pointer may be lost.或者,如果您在其位置添加另一个物理体,则原始指针可能会丢失。 Then if another body collides it will suddenly wake up.然后如果另一个身体碰撞它会突然醒来。 It depends on the circumstances and the version...这取决于情况和版本......

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

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