My character is in a physics world with hills in it. I’m using a SphereImpostor for the character and a MeshImpostor for the world. When they are on the side of a hill, they slide down the hill, which is good, but I’d like to be able to control how steep the hill needs to be before they slide. In my world, even a very shallow incline causes the character to drift slowly. I’ve tried changing the friction on both impostors up to 500, and it does slow things (including normal movement), but I’m still drifting on shallow inclines. I played with registerBeforePhysicsStep, even setting the impostor’s linear and angular velocity to 0, but still I’m drifting.
Is there any way to get the physics to let my character stop entirely, either through manipulating the variables (such as friction) or by manually modifying things in process (during the before physics step or somesuch)?
The Physics Engine used in RaananW’s playground is the default one : cannon.
Otherwise, it might be silly, but couldn’t your issue be solved by setting the body’s mass to 0 until the hill’s reached its critical steepness (or whatever condition you want) ?
That way, your body could still be subject to collision, impulse or angular velocity, if that’s something useful to you (I assume putting the physics body to sleep would forbid that).
There is difference is the way collision is being handled between the two cases. If a body is sleeping and a collision happens, it will wake up and the forces will be applied correctly. A mass : 0 body will cause a collision, but will stay in place.
And yes, I use cannon, which is usually the physics engine of my choice (mainly because I never really looked into Ammo too much…)
Changing the mass to 0 does exactly what I was hoping for! Thank you for that suggestion
One small caveat: I was hoping to taper the mass off so I would glide to a stop, but it looks like even minor changes to the mass will cause the object’s momentum to get reset to 0. I can work around that, but I thought I’d mention it. This is in Ammo; changing physics engines at this point in the project looks like it’ll be a big deal.
You mentioned before that friction on your bodies does slow the drift down. Maybe you could use that for your tapering, until at some point you set the mass to 0 to immobilize the body completely ? Then you could use this ‘immunity’ to restore your standard friction.
Please tell us how your attempts go, or if you fixed your problem.
Something else you can do is to “clamp” the objects position by manually setting it in the registerAfterPhysicsStep Observable. Note that you previously tried the before step
@Faber Nice, using friction for the slowdown is a great idea (assuming setting it doesn’t reset the momentum like mass does)! At the moment we have an implementation we are happy enough with to put into testing (where we stop you when you slow down enough), but I’ll keep this idea in case we want to revisit the solution
@jelster One thing I did try is to compare the mesh position from registerBeforPhysicsStep to registerAfterPhysicsStep, and it seemed to be the same. I’m pretty sure I cloned it (otherwise of course it would be the same), but now I can’t be sure. Anyway, you’re right that that would be another area to dig deeper into.
Thank you all for the help and suggestions! Having a lively community make such a difference
You know Babylon and its community never stops to amaze me. I’m far from an advanced user so I’m constantly looking for answers and explanations, it’s great to be able to give back a little !
If your problem is fixed though, please check the answer you think would help people with similar issues the most, so the topic is referenced under solved questions.