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
Fixate rotation (quaternion) #46
Comments
Hello, First I assume you work with the dev branch version of Cannon.js. What you need is a constraint to remove two rotational degrees of freedom for the body. There is no simple way of doing this right now but you could try adding a HingeConstraint and set the max- and minimum force of the positional parts to zero. hinge.equations.p2pNormal.maxForce=0; ...and the same for .minForce for them all. A less complicated solution would be to set the inertia to zero. This will make it behave like a static body but only in the rotational aspect. Example : body.inertia.set(0,0,0): I have not tested any of these solutions yet, but they work inside my mind :-) Stefan |
Thanks for your answer! Oh, I haven't even noticed the dev branch yet - was using master. Switching now. I just tried setting the inertia and invInertia to 0,0,0 (although I don't exactly understand how these are related) and it works like charm! Thanks a lot! Wow, switching to dev changed quite a lot! Things seem to be running smoother and objects move/fall more realistically IMO and big stacks of boxes aren't shaky anymore, awesome! Also, it seems like KINEMATIC body velocities are now changed when DYNAMIC bodies collide with them. Are these the new semantics of the motion state KINEMATIC? So the only difference between DYNAMIC and KINEMATIC is gravity? BTW: Any release plans for 0.5.0? |
Yeah - just need to fix a few things before the next release. I've done major restructuring regarding the solver, which created a domino effect of needed restructuring. I haven't really settled for a good abstraction of constraint equations yet, but perhaps I'll save that for a later release. The inertia and its inverse is calculated once using a given mass when creating the body. Should document this somewhere, and perhaps add an "updateMassProperties" function or similar. (the inertia tensor should really be a matrix but it's been represented by vectors since the start, storing only the diagonal entries of that matrix. Reason: didn't plan to support bodies with off-diagonal inertia in the beginning). Regarding dynamic and kinematic - I think you just discovered a bug there! I guess I forgot that detail when updating the solver. I'll get back to you when the bug is fixed. Thanks, |
Keep up the great work, Stefan! |
Hmm... Are you setting the mass of the kinematic bodies to zero? I think, if you do, the kinematicness will be fine :) |
Oh, with mass 0 it works as expected - thanks! Well, at the moment the objects should only behave STATIC and block the player from walking through. However, I might want to add movement to them later, so I thought it would be a good idea to use the KINEMATIC motion state already. So, I guess this issue can be closed. :) Oh, one more thing, maybe you have an idea: Is there an easy way to detect whether an object is currently standing on another object (i.e. "touching the ground")? I tried checking the y-velocity against 0 but that's not a very solid way (thinking of jumping and that moment when the object reaches the peak of the jump). |
Good :) You can always check if the object is sharing a contact with some other object. This can be done by looping over all ContactEquations in Just noticed that the Another simpler solution: just check whether the object had a contact or not since the last jump. This is already implemented in the FPS demo. This solution is not the best (user can jump whenever any contact with it is generated), though it works. |
Thanks for your help! So (I'm afraid iterating through all |
Yes, correct! Stefan |
Thank you very much, Stefan! I'm sorry if I have to bother you one more time, but either there is a bug in the This is how I set up the plane: plane = new CANNON.Plane();
planeBody = new CANNON.RigidBody(0, plane, groundMaterial);
planeBody.quaternion = new CANNON.Quaternion(-0.5, 0.5, 0.5, 0.5);
planeBody.position = new CANNON.Vec3(0, 0, 0);
world.add(planeBody); Did I miss something here? I really appreciate your support! |
No problemo :) Looking at the stacks demo (the box/plane scene), the normals are indeed pointing downwards into the plane. But since we have the box as
I hope this helps :) |
Setting the quaternion from an angle was my first approach but I decided to go the not-so-readable-way of setting it manually to ensure precision (thinking of a huge plane, dividing or even only using pi for the angle calculation might be an issue for increasing distances to the center of the plane). You are right, I just had to check if Once again, thank you very much! (finally closing here ;)) |
Fix convex triangle pillars for heightfields with negative values
First of all: Great work! Performant physics in the browser, written in JS - that's truly impressive.
I am currently experimenting with cannon.js together with KickJS as a WebGL-based game engine and have a question regarding modeling of a scene.
TL;DR Is there a way to fixate the quaternion of an object (along an axis) in order to prevent it from falling over?
My cannon.js world currently consists of
Now I want to allow users to move (from first person) through the world. So I create a sphere with radius=0.5, y=0.5, motion state DYNAMIC (i.e. rolling on the ground) and bind it to the camera position (but not the rotation because I don't want the camera in fact to be rolling around). When they press the WASD/cursor-keys I increase the corresponding axis velocity of the sphere and push it in that direction. So far so good, everything works great: No running through boxes (collisions) and the player sphere drops from height by gravity. Awesome!
Now I want my player to be a little greater. I could just increase the sphere radius, but that would make him collide with the boxes from more distance too, so he can't get close to them anymore. So instead of the sphere I could use a rectangular box with height=2, width=1, depth=1. Or a cylinder with radius=1, height=2. However, when pushing that box/cylinder as the player moves It will fall down (and therefore not collide with the floating boxes anymore). And that's my problem right now.
Here are some things I have tried to work around it:
Is there a way to fixate the quaternion of an object (along an axis) in order to prevent it from falling over?
Since I don't know any other options I could try, I would really appreciate your help!
The text was updated successfully, but these errors were encountered: