Search Unity

transform.position vs Rigidbody.position for player - camera position matching

Discussion in 'Scripting' started by PauliusAb, Jul 25, 2021.

  1. PauliusAb

    PauliusAb

    Joined:
    Jul 25, 2021
    Posts:
    1
    My questions are:
    1) Is reading object's position faster with Rigidbody.position than transform.position?
    2) Are the two methods' values updated at a different rate?

    I am creating an FPS controller with camera as a separate object (not a child) from the player. I am moving the player in FixedUpdate() and the camera separately in Update() in order to provide a more smooth and reactive control. At the end of the Update() cycle I am moving the camera to the same spot as the current Player position is. To my surprise, matching the position using transform.position shows better results than using Rigidbody.position, which makes the game view jittery.

    I've read that moving an object with transform.position is significantly slower than using Rigidbody.position, but I couldn't find if reading the position using these two methods takes different time.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,689
    This is not because of the performance but rather because of the mismatch between Update() and FixedUpdate() timing.

    Here is some timing diagram help:

    https://docs.unity3d.com/Manual/ExecutionOrder.html