Change physics impostor's mass to 1 after set to 0

Hello!

After my attempt over at the Wingnut Chronicles, I was wondering if the was any way to set the mass of a physics impostor after it has been made. Like push “s” set mass to 1. push “j” set to 0. something like that, except just the change part.

pinging @trevordev

I tried object.physicsImpostor.setmass(1);, but that either crashed the playground or wouldn’t work at all.

If you create an impostor with mass 0 it becomes kinematic so that might be the issue. Try creating it with mass 1 and then set its mass to 0. Then see if changing the mass works. Share a playground if you still have issues.

Thanks, I’ll try that out.

1 Like

@Deltakosh you can make changes to the bjs docs, right? But the syntax for setmass is incorrect. I think. Here: PhysicsImpostor - Babylon.js Documentation

Like my reply to you, I tried

object.physicsImpostor.setmass(1);

because that is what I thought the docs were telling me what to do. I now have it working, as it is actuallyobject.physicsImpostor.setmass = 1;. I got it figured out now. @trevordev thanks for the explanation it works great.

I you click on the “find examples in playground” link on the doc page the syntax for examples use parenthesis and not the equals sign.

Thanks for the help, and happy fixing.

@Givo i think there is a casing issue. It’s setMass not setmass. I tried to repro this but it seems to be working here: https://www.babylonjs-playground.com/#BXII#77

Note to self:

if (using .setmass) { use .setmass = *number*; } else if (using .setMass) { use .setMass(*number*); }

Thanks for the help! Capitals make all the difference.

1 Like

Hello!
Thanks you all to solve the problem about how to change the mass of a physics impostor. Unfortunately, I met a new problem. I create a button, which as I click it then the mass of a physics impostor will increase 1 kg. However, when the mass reached 3 kg, I click the button again, the physics impostor begin to move, just like apply a force on it. I don’t know which step is wrong?

Hello and welcome Ethan,

You should create a new post to get more views :wink:

Thanks for your advice. I will create a new post later. :grin: