Search Unity

Smooth rigidbody.AddForce()

Discussion in 'Scripting' started by doubleJ, Jun 12, 2013.

  1. doubleJ

    doubleJ

    Joined:
    Feb 10, 2013
    Posts:
    33
    Greetings guys,

    I would like to know is it possible to add force to an object and make it look smooth. I am using very simple code to give acceleration to an object.

    Code (csharp):
    1. void FixedUpdate()
    2.     {
    3.         if (landed)
    4.         {
    5.             rigidbody.AddForce(acceleration, 0f, 0f, ForceMode.Acceleration);
    6.         }
    7.     }
    Right now, when force is being added to an object, its movement looks a bit "jaggy". Any ideas where problem can exist? :confused:

    (P.S. Objects Physic Material has no friction...)
     
    Tilo_K likes this.
  2. george-daters

    george-daters

    Joined:
    Jan 22, 2013
    Posts:
    35
    I've not come across any smoothing issues with the physics unless your frame rate is very low. I think it is more likely that your jaggyness comes from the camera updating its orientation before/after the physics have been applied. I had this issue in my game and it was fixed by updating the camera position inside FixedUpdate rather than Update
     
    etziok, Tilo_K and minhthong095 like this.
  3. doubleJ

    doubleJ

    Joined:
    Feb 10, 2013
    Posts:
    33
    Thanks george, you are actually right... Changing Update() inside my camera script to FixedUpdate() solved this problem...
     
  4. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    you should change that again to LateUpdate
     
  5. noobme

    noobme

    Joined:
    Mar 18, 2013
    Posts:
    45
    I have change my camerascript to FixedUpdate() but the problem of acclerating still exists
     
    chernobyyl likes this.
  6. minhthong095

    minhthong095

    Joined:
    Jun 18, 2016
    Posts:
    1
    oh mann, u save my day
     
  7. totovr92

    totovr92

    Joined:
    Aug 2, 2018
    Posts:
    1
    I changed it in this way to do it more smoothly:

    Code (CSharp):
    1.     public float rotationPoint = 0.5f;
    2.  
    3.     public Rigidbody rb;
    4.  
    5.     void Start()
    6.     {
    7.         rb = GetComponent<Rigidbody>();
    8.     }
    9.  
    10.     public void OnTriggerStay(Collider collider)
    11.     {
    12.         if(collider.gameObject.CompareTag("RotatePointOne"))
    13.         {
    14.             rb.AddForce(rotationPoint, 0, 0, ForceMode.Impulse);
    15.         }
    16.     }
     
  8. etziok

    etziok

    Joined:
    Nov 16, 2020
    Posts:
    1
    Genius <3