Search Unity

Why do they still bounce?

Discussion in 'Physics' started by OlivierPons, Oct 7, 2018.

  1. OlivierPons

    OlivierPons

    Joined:
    Sep 20, 2014
    Posts:
    28
    I've made things like you can see in many tutorials and forums:
    - created Physic Material I called "`No bounce`"
    - set `Dynamic Friction = 0` and `Static Friction = 0`
    - created a cube and add a `Box collider` with `Material = "No Bounce"`
    - set `Mass = 1`, `Drag = 0` and `Angular Drag = 0`
    Now I add another cube for the ground, made it very large and added a `Box collider` with `Material = "No Bounce"`
    I have 2 problems:
    - when they collide, the cube bounces (whereas it shouldn't with my configuration)
    - I've made a script and attached it to the cube, to change the velocity, and set it to `0` when there's a collision:

    Code (CSharp):
    1.     using UnityEngine;
    2.  
    3.     public class CubeProperties : MonoBehaviour
    4.     {
    5.         private Rigidbody _rb;
    6.         private bool _landing;
    7.  
    8.         private void Start()
    9.         {
    10.             _rb = GetComponentInParent<Rigidbody>();
    11.         }
    12.  
    13.         public void OnCollisionEnter(Collision collision)
    14.         {
    15.             Debug.Log("Collision");
    16.             _landing = true;
    17.         }
    18.    
    19.         public void FixedUpdate()
    20.         {
    21.             if (!_landing) {
    22.                 return;
    23.             }
    24.             _rb.velocity = Vector3.zero;
    25.             _landing = false;
    26.         }  
    27.     }
    So at the first collision, I try to instant stop the cube with `_rb.velocity = Vector3.zero;`. But *changing velocity has no effect*, I dont understand why. I've tried with many value to see what happens... but nothing happened.
    The only thing I can add, and it's working, is: `AddForce()` I tried to a negative value, but this doesn't work either.
    What did I forgot?
    Here's a video I hope this is easy to understand (and I hope I'm allowed to help with a video):

     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    you set landing = false;, so the FixedUpdate part only runs once ?
     
  3. OlivierPons

    OlivierPons

    Joined:
    Sep 20, 2014
    Posts:
    28
    If you watch the video you'll see it runs when it hits something, but once. This should give something like:
    - "you hit something, you instant stop"
    - Unity physics takes control again, and if it has to fall, it falls again or it goes to sleep in .5 s
    - if it falls again, restart the loop

    This is the "basic" code. So it should instant stop when it hits something with no rebound at all.