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

Question Speed of an object

Discussion in 'Scripting' started by Losborne22, Oct 9, 2023.

  1. Losborne22

    Losborne22

    Joined:
    Sep 14, 2023
    Posts:
    3
    I am stuck trying to figure out how to maintain the constant speed of an object in Unity. When the object bounces back and forth from other objects it gets faster and faster, and I want to learn how to make sure it stays at a constant speed.
     
  2. John_Leorid

    John_Leorid

    Joined:
    Nov 5, 2012
    Posts:
    624
    How do you set the speed?
    rigidbody.velocity = transform.forward * 10;
    inside the Update or FixedUpdate Method results in constant speed. Whenever the speed changes, it is set back to the fixed value, every frame.
     
  3. zulo3d

    zulo3d

    Joined:
    Feb 18, 2023
    Posts:
    541
    Code (CSharp):
    1. GetComponent<Rigidbody>().drag=1.0f;
     
  4. Losborne22

    Losborne22

    Joined:
    Sep 14, 2023
    Posts:
    3
    Thank you I will try these