- Home /
Stop physics without Time.timeScale
Hi. I'm looking for a cheap way for stopping the physic simulation.
In my game you basically roll around a ball using physics. When the ball hits the finish, I want the ball and every other rigidbody to stop. However I also want to use particle effects afterwards, so I can't set Time.timeScale
to 0.
I've tried to set every(Rigid)bodys velocity to 0 during FixedUpdate, but they were still moving slowly under gravity. Besides this seems too crude to me anyways.
Thanks alot.
Answer by zombience · Jun 10, 2013 at 03:18 PM
have a manager somewhere that registers all of your rigidbodies. then, when you need to stop them, go through the array or list and set something like:
public List<Rigidbody> physObjects = new List<Rigidbody>();
public void AddRigidbody(Rigidbody r)
{
physObjects.Add(r);
}
public void DisablePhysics()
{
foreach(Rigidbody r in physObjects)
{
r.isKinematic = true;
}
}
public void EnablePhysics()
{
foreach(Rigidbody r in physObjects)
{
r.isKinematic = false;
}
}
right and for a true pause script (so you can resume later) you would save the velocity and angularVelocity of each Rigidbody and restore them on resume.
Thanks for your reply. I tried:
void DisablePhysic(){
Rigidbody[] rigs = (Rigidbody[]) GameObject.FindObjectsOfType(typeof(Rigidbody));
foreach (Rigidbody r in rigs){
r.velocity = Vector3.zero;
r.useGravity = false;
r.is$$anonymous$$inematic = true;
}
}
,but I got an error: Actor::setLinearVelocity: Actor must be (non-kinematic) dynamic! The movement seems to stop correctly though.
$$anonymous$$aybe you are trying to set the velocity to something in another script or part of the script. If you double click on the error what line of code does it send you to?
hmm, strange error. not sure. it appears that unity believes that the rigidbodies are kinematic BEFORE you set the velocity to zero (kinematic rigidbodies have no velocity). if you want them to stop and never need to start them again at their previous velocity, however, that step is redundant to is$$anonymous$$inematic = true;
if your original question is answered, don't forget to mark this question as answererd.
Thanks a lot guys. Seems like I had a kinematic rigidbody left, which I wasn't aware of. It works perfectly now.
if your original question is answered, don't forget to mark this question as answererd.
I always do this, when I'm happy with the answer.
Your answer
Follow this Question
Related Questions
Friction between two rigidbodies 0 Answers
Moving a player with Rigidbody 2 Answers
Disable inertia tensor calculations on rigidbody? 0 Answers
Problems with Configurable joint in 2d Configuration 0 Answers
Raycast on ball game 2 Answers