Search Unity

Resolved Player gets launched when it's collider is enabled inside another collider

Discussion in 'Physics' started by patrykszylindev, Nov 19, 2020.

  1. patrykszylindev

    patrykszylindev

    Joined:
    Oct 28, 2019
    Posts:
    23
    I'm working on dash ability, and I'd like the unity engine to take care of the object positioning after the collision is resolved.

    My current approach is as following;
    1) I press the SPACE key to trigger ability
    2) I disable the collider of the player
    3) When dash reached the calculated position I then reenable the collider
    At that point, the collider is re-enabled inside another collider and the player gets launched into the opposite direction (sometimes it gets launched into World's forward direction). I've attached a gif to illustrate the issue.

    ezgif.com-gif-maker (1).gif

    Any ideas as to why this is happening?
     

    Attached Files:

  2. patrykszylindev

    patrykszylindev

    Joined:
    Oct 28, 2019
    Posts:
    23
    I've fixed this issue by setting rigidbody's velocity
    Code (CSharp):
    1. rigidbody.velocity = Vector3.zero
    before re-enabling colliders.

    Here's the result:

    ezgif.com-gif-maker (2).gif
     
    Last edited: Nov 20, 2020