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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Constant velocity when adding force to a ridgidbody

Discussion in 'Physics' started by Maskedr, May 5, 2015.

  1. Maskedr

    Maskedr

    Joined:
    May 5, 2015
    Posts:
    10
    I want to move an rigidbody non-kinematic by applying a force but I want to have a constant velocity. By adding a force in FixedUpdate() each time is called, will increase the object velocity. I could check the object velocity and if is less or bigger then the one I want I could updated with the value I want.... but this is not a good approach according by unity documentation:

    http://docs.unity3d.com/ScriptReference/Rigidbody-velocity.html

    So i need guidance to understand how to move an object with constant speed by applying a force!

    Thanks in advance!
     
  2. waythewanderer

    waythewanderer

    Joined:
    Apr 6, 2015
    Posts:
    92
    You can try applying an opposite force, or use rigidbody.MovePosition
     
  3. Maskedr

    Maskedr

    Joined:
    May 5, 2015
    Posts:
    10
    From unity documentation if you have a rigidbody non kinematic you should modify the position only by applying a force.
    Opposite force? What magnitude?... how can I create a system with force and opposite force which will keep the velocity constant?
     
    Last edited: May 6, 2015
  4. waythewanderer

    waythewanderer

    Joined:
    Apr 6, 2015
    Posts:
    92
    You can try increasing the drag to a value that will keep the velocity constant. Try adding a force until it accelerates to the desired velocity, then stop applying that force and turn off drag.
     
  5. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    you can use velocity if its easier... sure it can produce unrealistic results, but depending on your needs that might not matter.

    they say that because overriding the velocity value means you negate gravity and collision forces. MovePosition is a nice way to move a rigidbody with good accuracy, especially if you have a target velocity
     
  6. Maskedr

    Maskedr

    Joined:
    May 5, 2015
    Posts:
    10
    Thanks a lot guys for help!

    MovePosition is the easiest way to control the object but velocity is another good approach. My bad that I was looking to find a solution to avoid using something else then force.

    How the usage of move position and velocity on non kinematic will affect the GPU on iOS devices?
     
  7. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    All of the methods will have the same impact on GPU. (MovePosition/Velocity/AddForce)

    Just dont use Transform.Translate/Rotate
     
  8. Maskedr

    Maskedr

    Joined:
    May 5, 2015
    Posts:
    10
    Thx a lot!
     
  9. Todd-Wasson

    Todd-Wasson

    Joined:
    Aug 7, 2014
    Posts:
    1,077
    Set the force to 0 when the velocity reaches the velocity you want.