cannon.js icon indicating copy to clipboard operation
cannon.js copied to clipboard

Lock body rotation on some axes (x and z)

Open ziadsarour opened this issue 6 years ago • 6 comments
trafficstars

Hi everyone,

First of all, what a lib ! Really great work @schteppe, I can't imagine what was the amount of work required to develop that library !

I've searched for answers but I didn't found anything :/ What I want to do is to lock my body rotation on axes x and z (I want to prevent my character to fall when jumping or colliding with others bodies).

Thank you for your help

ziadsarour avatar Jul 06 '19 04:07 ziadsarour

I've found a solution to prevent my character falling by setting the angularDamping to 1. I can continue my game with this solution but if someone knows how to lock axes, feel free to share :)

ziadsarour avatar Jul 06 '19 16:07 ziadsarour

In my character demo I'm using the body.fixedRotation = true; on the CANNON.Body character capsule. Then I'm just rotating the model attached to the capsule to my liking. In the end, an upright capsule is always a capsule, no matter how it's rotated on the Y axis, so why even bother with it. 🙂

Though maybe setting angularDamping to 1 works just as well?

I think I also started with the same idea as yours, where I wanted to lock the body on X and Z axes, but either I didn't find a solution or there was a problem with it, so I just used this.

swift502 avatar Jul 06 '19 16:07 swift502

Cool demo.

On Sat, Jul 6, 2019 at 9:29 AM swift502 [email protected] wrote:

In my character demo http://jblaha.art/examples/characters.html I'm using the boxBody.fixedRotation = true; on the CANNON.Body character capsule. Then I'm just rotating the model attached to the capsule to my liking.

I think I also started with the same idea as yours, locking the body on X and Z axes, but either I didn't find a solution or there was a problem with it, so I just used this.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/schteppe/cannon.js/issues/422?email_source=notifications&email_token=AAF32QE4BOLYV6YD45XMI33P6DCAPA5CNFSM4H6SRDBKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZK4Q6I#issuecomment-508938361, or mute the thread https://github.com/notifications/unsubscribe-auth/AAF32QBZUG453EXQKH54LOTP6DCAPANCNFSM4H6SRDBA .

DeathBot9 avatar Jul 06 '19 16:07 DeathBot9

@swift502 That is a cool demo! Great job!

jfelrod1960 avatar Jul 08 '19 01:07 jfelrod1960

@swift502 awesome solution ! Just starting with game dev, capsule with 3 spheres (like in your own project) is pretty clever ! Thank you :)

ziadsarour avatar Jul 08 '19 01:07 ziadsarour

As specified in this spectrum post (from pmndrs/use-cannon), it's possible to set a angularFactor in your body object to specify the dimensions you want to be available for rotation.

bastienrobert avatar May 17 '21 13:05 bastienrobert