Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

RigidBodies keep on sliding,colliding and takes much longer to come to rest.

Discussion in 'Scripting' started by SalmanJaved, Dec 2, 2019.

  1. SalmanJaved

    SalmanJaved

    Joined:
    Sep 12, 2019
    Posts:
    10
    I have created Angry Birds like game. It has a sling shot that fires projectiles at a castle made of rigid bodies.
    what happens is that when i fire projectile from sling shot ,my camera follows it and resets when the ball gets slow, its good according to code (i-e is check "IsSleeping()" condition if true reset camera for next fire)

    The problem is when the ball hits castle some times it get stuck in castle rigid bodies, the rigid bodies keeps on slowly sliding to ground and even the ball does not moves faster "The camera does not resets until all rigid bodies collided with ball have completely stopped motion, which takes longer to reset camera.

    Kindly tell me some adjustments for this... Thank You
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,971
    Easiest is to probably add Physic materials with more drag on them, or just turn up the drag on your rigidbodies so they come to rest sooner. Have you tried this approach?
     
  3. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,835
    Physics is messy. Whatever else you do, your camera should probably have some kind of timeout where it eventually gives up and resets even if the objects have not stopped moving.
     
    Kurt-Dekker likes this.
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,971
    Another approach building on what @Antistone said above is to have code to detect the first impact, then start increasing the rigidbody drag in real time until everything stops moving. Once it stops, reset the drag to your base value, whatever that is, clear the boolean you set when you detected first impact, and repeat the cycle with the next fling.
     
  5. SalmanJaved

    SalmanJaved

    Joined:
    Sep 12, 2019
    Posts:
    10
    Thanks Kurt, i will try it. Currently i solved it using velocity vector magnitude of ball.
     
    Kurt-Dekker likes this.