Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why don't any of the examples use applyForce / applyImpulse? #257

Closed
AndrewRayCode opened this issue Jan 18, 2016 · 4 comments
Closed

Why don't any of the examples use applyForce / applyImpulse? #257

AndrewRayCode opened this issue Jan 18, 2016 · 4 comments

Comments

@AndrewRayCode
Copy link

I'm trying to debug my jumping code (as mentioned on Twitter) and when looking at the FPS example code, http://schteppe.github.io/cannon.js/examples/js/PointerLockControls.js, to make the player jump, the velocity property of the body is mutated directly:

var velocity = cannonBody.velocity;

...

        case 32: // space
            if ( canJump === true ){
                velocity.y = jumpVelocity;

Why do you do this instead of using applyForce or applyImpulse? Are those innappropriate to use for applying movement forces to a player?

@schteppe
Copy link
Owner

If you run applyForce or applyImpulse, it will add to body.force or body.velocity. That makes the jump height unpredictable, which isn't acceptable when making a game. Instead, if you set the absolute value of the velocity, you always know what height you get.

@AndrewRayCode
Copy link
Author

ah ok, thanks!

@AndrewRayCode
Copy link
Author

On these lines of the FPS demo, PointerLockControls.js

    // Add to the object
    velocity.x += inputVelocity.x;
    velocity.z += inputVelocity.z;

Isn't that the same as applyImpulse?

@schteppe
Copy link
Owner

Yeah, it is! But applyImpulse can add angular velocity too, depending on where you apply the impulse.

kylebakerio added a commit to kylebakerio/aframe-physics-system that referenced this issue Sep 4, 2021
I think many a newbie has tried to jump into this library and been confused at not understanding how to apply forces. The use of velocity directly is far more predictable than applyImpulse, which makes more sense for programatic use generally. See [here](schteppe/cannon.js#257) for some validation of what I'm talking about, though I think it's also something easy to experience if you try creating a demo following this readme, and may lead to poor initial user experiences with CANNON, as described e.g. [here](https://aframevr.slack.com/archives/C3WGUL4K0/p1617736493000900).

Perhaps some glitch demos should be shared here that would be a bit easier to digest for beginners as well?
kylebakerio added a commit to kylebakerio/aframe-physics-system that referenced this issue Sep 4, 2021
I think many a newbie has tried to jump into this library and been confused at not understanding how to apply forces. The use of velocity directly is far more predictable than applyImpulse, which makes more sense for programatic use generally. See [here](schteppe/cannon.js#257) for some validation of what I'm talking about, though I think it's also something easy to experience if you try creating a demo following this readme, and may lead to poor initial user experiences with CANNON, as described e.g. [here](https://aframevr.slack.com/archives/C3WGUL4K0/p1617736493000900).

Perhaps some glitch demos should be shared here that would be a bit easier to digest for beginners as well?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants