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 How to get Rigidbody position after calling MovePosition

Discussion in 'Physics' started by Vukelic, Jun 6, 2023.

  1. Vukelic

    Vukelic

    Joined:
    Apr 3, 2017
    Posts:
    1
    I'm trying to get the information about the new position of a rigidbody after calling MovePosition. This is working as expected for non-kinematic rigidbodies, but for kinematic rigidbodies the rigidbody.position after calling rigidbody.MovePosition(...) remains unchanged. Look at the example below:
    Code (CSharp):
    1.  
    2. private void FixedUpdate()
    3. {
    4.     rb.MovePosition(new Vector3(10, 10, 10));
    5.     Debug.Log($"rbPos: {rb.position}, tPos: {transform.position}, " +
    6.         $"rbVel: {rb.velocity}, pointVel: {rb.GetPointVelocity(transform.position)}");
    7. }
    8.  
    This is printed:
    rbPos: (0, 0, 0), tPos: (0, 0, 0), rbVel: (0, 0, 0), pointVel: (0, 0, 0)


    I cannot use any form of manual caching to store this target position because I'm writing a library. So MovePosition could be called from the user code and I need to access the position information later that frame from the library code.

    Is there a way I could access information about target position, velocity or anything else that could help me to extract target position of a rigidbody for the next FixedUpdate?
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,277
    It doesn't happen immediately, it happens when the simulation runs and no, it isn't anywhere you can retrieve it.

    In 3D, using a Dynamic Rigidbody performs an instant teleport to that position i.e. it doesn't work as a Kinematic one does. In 3D it's designed for Kinematic only.