Search Unity

How to step the physics simulation and know where your rigidbody position winds up

Discussion in 'Physics' started by CPlusSharp22, Jul 19, 2019.

  1. CPlusSharp22

    CPlusSharp22

    Joined:
    Dec 1, 2012
    Posts:
    111
    When I apply velocity to a rigidbody in FixedUpdate like so:

    Code (CSharp):
    1. void FixedUpdate()
    2. {
    3.     rigidbody.velocity = new Vector3(Input.GetAxis("Horizontal", 0, Input.GetAxis("Vertical");
    4.     // Has transform.position updated yet?
    5. }
    When or where can I check transform.position for the result? How do I know where this rigidbody/gameobject is going to wind up in this frame?

    I ask because I'm trying to create a multiplayer server where the movement can be predictable based on input. If I know the player input, I should be able to send that to my server. But then my server has to send the player his or her next position. But, with rigidbodies, that result does not occur in the same FixedUpdate() does it? I'd have to wait until the next FixedUpdate() to query the position.

    Example:
    Frame 1
    -I push Forward input
    -Velocity gets applied to rigidbody

    Frame 2
    -Query transform.position

    Is there anyway to instead query the Frame 2 position in Frame 1 I guess is what I'm asking?