I have a ball that I throw around. When it hits the ground, I would like to throw this ball and when it touches the ground I want it to stop at its place. Currently it keeps sliding. The problem is that if I use isKinematic and set it to true, I get the following error
Actor::setLinearVelocity: Actor must
be (non-kinematic) dynamic!
So I’d prefer to avoid setting isKinematic to true
The error is just saying you can’t push a frozen object, so unfreeze it first. In front of all your pushes, add:
// going to push, so unfreeze me if needed:
if(ball.rigidbody.isKinematic) ball.rigidbody.isKinematic=false;
Of course, it will only work if you other code is “only push when needed.” For example, the standard charController code always tries to move, using speed (0,0,0) when stopped. I’ve also used isKen/not-Ken in OnCollision: “if I was hit hard enough, unfreeze me.”
The other way to do it, which might work, is to set velocity to 0 each frame (when stopped.) The problem is the physics step seems to add a tiny bit of speed first, then slide that much (but I may have only done it in Update.) One thing I’ve never tried is saving the position when “frozen” and resetting it each FixedUpdate.
I’ve also never tried manually putting it to sleep (mostly because isKen works fine and is so similar.)
I assume from your comments that you are detecting the collision between the ball and the ground. If so, you can set the Rigidbody.constraints flags to keep it from moving, and clearing the flags when the player picks up/throws the ball. It would probably be best to zero out out the velocity vector at the same time.