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. Dismiss Notice

2 rectangles, realistic collision on a side?

Discussion in 'Physics' started by EwnT9, Jun 7, 2017.

  1. EwnT9

    EwnT9

    Joined:
    Apr 20, 2017
    Posts:
    31
    Hi,
    I am trying to make a truck colliding with a small car. When the truck collides with the car, and the car is in front of the truck but slightly on the side, instead of rotating towards the left, it goes a little bit left then right and is being pushed on its transform.right. I would have expected the car to rotate at least 180° and to go backwards, even if it touches the truck again. I tried to play with mass, with the size of the collider box, ...

    Here is a gif :

    wrong_direction.gif
     
    Last edited: Jun 8, 2017
  2. eXonius

    eXonius

    Joined:
    Feb 2, 2016
    Posts:
    207
    It's not easy to follow you on what's happening and what you want to achieve. Maybe a picture would help.
     
  3. EwnT9

    EwnT9

    Joined:
    Apr 20, 2017
    Posts:
    31
    I edited my message.
     
  4. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,988
  5. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Gif hard to follow too.
     
  6. eXonius

    eXonius

    Joined:
    Feb 2, 2016
    Posts:
    207
  7. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,507
    Is the large block actually moving or are you just translating it from position to position? In other words, is its body moving under its own velocity / using Rigidbody.MovePosition. If you're just repositioning it then it's not moving through space so it'll just become overlapped which will cause physics to only solve the overlap.
     
    EwnT9 and eXonius like this.
  8. EwnT9

    EwnT9

    Joined:
    Apr 20, 2017
    Posts:
    31
    Yes great, thank you MelvMay it works now. I was using
    Code (CSharp):
    1. transform.position += Vector3.forward*speed;
    I now use this :
    Code (CSharp):
    1. GetComponent<Rigidbody>().velocity = (Vector3.forward*speed) * 50;
     
    MelvMay likes this.