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

Adding force that lasts for some time

Discussion in 'Physics' started by skuky123, Apr 25, 2021.

  1. skuky123

    skuky123

    Joined:
    Feb 7, 2021
    Posts:
    14
    Hello!

    How to make object being forced by force to move at faster speed for some ammount of time without droping the speed, after time is done then speed should go down?
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,529
    Can you please rephrase that so it's easier to understand.
     
  3. skuky123

    skuky123

    Joined:
    Feb 7, 2021
    Posts:
    14
    Okay, Ill try!

    So I have a ball like in golf, and I have ability that makes ball being forced to move faster for some time(4secs), after that it slows down to 0 movement. So lets say my ability is on "P", I press P, ball gets forced to move at bigger speed for 4 seconds, and after that it slows down to 0. In those 4 seconds ball should have a constant speed without slowing down, after 4 seconds passed, then ball slows down. I hope you understood me. Sorry English is not my better side.
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,529
    Sounds like you need to turn on/off drag. There's both linear and angular drag and these act approximately like air resistance in the sense that they apply even if the ball isn't contacting anything. When in contact you can additionally use PhysicsMaterial2D.friction.

    For example, if the drag is set to zero then nothing will slow it down and it'll continue to move. After 4 seconds or whenever you like, set the drag to a value that'll slow it down how you like.
     
    skuky123 likes this.
  5. skuky123

    skuky123

    Joined:
    Feb 7, 2021
    Posts:
    14
    Great! Sounds like the thing I needed!

    Will it work on the same way if the ball is in the air(values of gravity and mass are 0)
     
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,529
    If by "it" you mean the drag then yes, absolutely.

    NOTE: I don't know what you mean by mass of zero as that isn't allowed on a Dynamic body.
     
    skuky123 likes this.