Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved Ruby's Adventure: Ruby constantly pushed after collision with enemy robot

Discussion in 'Getting Started' started by ngrash, Jan 14, 2022.

  1. ngrash

    ngrash

    Joined:
    Jan 10, 2022
    Posts:
    4
    Edit: Setting Body Type to kinematic does not fix the problem. See my answer below.

    Edit: See my other answer below for a solution that actually works.

    Prior to posting this, I searched the forum and the internet and I think I found a solution to my problem. I'm posting this nonetheless because I think others might struggle too and because I am not sure if my fix is correct or has any implications I am not aware of.

    I am following the awesome tutorial Ruby's Adventure: 2D Beginner and noticed a problem while playtesting: When Ruby collides with a robot she gets pushed away and somehow the force keeps pushing her long after she lost contact with the robot.

    I found out that changing Body Type of Ruby's Rigidbody 2D component from Dynamic to Kinematic solves the problem. I searched the tutorial to see if I missed the step where I was told to set the type to kinematic and I could not find it. Did I miss something?

    I created a screen recording to help clarify what I am seeing:


    Is my fix the correct solution for the problem? Did I miss something in the tutorial or is the tutorial even missing something?
     
    Last edited: Jan 15, 2022
  2. RichAllen2023

    RichAllen2023

    Joined:
    Jul 19, 2016
    Posts:
    1,026
    Well done for sorting it but I don't think it's you that's missing anything it's the tutorial itself that's ever so slightly out of date.
     
    ngrash likes this.
  3. ngrash

    ngrash

    Joined:
    Jan 10, 2022
    Posts:
    4
    I just realized that setting Body Type to kinematic disables collision checking with all objects except the robot, so my solution does not really work. What else could I try?
     
  4. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
  5. ngrash

    ngrash

    Joined:
    Jan 10, 2022
    Posts:
    4
    Reading more about the Rigidbody 2D in the excellent documentation, I found the Linear Drag property. Setting it to 10 (default was 0) fixes the problem nicely.

    This makes sense to me. Since I disabled gravity (by setting Gravity Scale to 0) as the tutorial suggests, there is nothing stopping Ruby from floating endlessly when she gets momentum. I think of it like an object in outer space that is missing any form of drag and therefore never comes to a halt. By simulating drag Ruby will still be pushed but comes to a halt shortly after the pushing force stops which makes for a nice effect of being pushed around by the robot.

    I still wonder why I could not find a solution in the tutorial and why the problem is not mentioned in the mega thread (thanks @JeffDUnity3D for pointing me towards it).