- Home /
Moving and SweepTesting a kinematic Rigidbody multiple times within a single FixedUpdate() call
I'm writing some custom movement code for a 2D platformer character, using a kinematic Rigidbody and a C# script that can call SweepTest() and MovePosition() two or more times each during its FixedUpdate() function. However, calling rigidbody.MovePosition() doesn't seem to immediately update the rigidbody's position variable to the new position. For example the following function will print the same value for position 1 and position 2:
void FixedUpdate () {
Debug.Log("Position 1: " + rigidbody.position);
rigidbody.MovePosition(rigidbody.position + new Vector3(0.0f, 1.0f, 0.0f));
Debug.Log("Position 2: " + rigidbody.position);
}
I assume this means that the Rigidbody is only being moved at the end of the physics step. If this is the case, how can I move a kinematic Rigidbody and call SweepTest() from its new position in the same FixedUpdate() call?
Try using yield or make a closures ?:
yield return null;
next fixed update code goes here...
Your answer
![](https://koobas.hobune.stream/wayback/20220613093927im_/https://answers.unity.com/themes/thub/images/avi.jpg)