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

Freeze a Player's Movement

Discussion in 'Scripting' started by Thunderline-Studios, Oct 6, 2019.

  1. Thunderline-Studios

    Thunderline-Studios

    Joined:
    Jul 27, 2019
    Posts:
    4
    Hello, I am posting this on forums because I can't post on Unity Answers for some reason, I can't even log in

    I have been working on a flying car vehicle for a while now for my game, and I was having trouble with this bug.

    You can enter the car just fine standing still, but if you hold your movement keys going in to the vehicle and continue holding them down, you will keep going for about a second. I have disabled the player script, and it will still move. Video showing this: https://imgur.com/a/Jw7Psg6

    If you know an answer, please reply ASAP, thanks :)
     
  2. berzii

    berzii

    Joined:
    Jun 25, 2016
    Posts:
    14
    Hi there,
    One solution for your problem is just set the velocity of your rigidbody to zero as soon as you enter the vehicle.
    So try something like that:
    Code (CSharp):
    1. rigidbody.velocity = Vector2.zero;
     
    shawndingo likes this.
  3. shawndingo

    shawndingo

    Joined:
    Oct 4, 2018
    Posts:
    83
    Another way is to use a bool. But doing as @berzii stated should also do the trick.
     
  4. Thunderline-Studios

    Thunderline-Studios

    Joined:
    Jul 27, 2019
    Posts:
    4
    Thank you so much! This worked! I should have thought about Rigidbodies!