- Home /
Question by
Spiele_Spiela · Apr 13, 2020 at 03:30 PM ·
physicsanimatorcoroutinerigidbody2d
coroutine cannot control physics of an object with animator
Hi,
I have a Gameobject with the TEST script and an animator.
The TEST script does not move the Gameobject, as long as the animator (or apply root motion) is enabled. The problem is that I need to sometimes apply root motion (as some animations need it) but I also want to use coroutines for the movement (so I can easily swap out different coroutines if I want different movement patterns). Any tips?
public class TEST : MonoBehaviour
{
public Rigidbody2D rb;
private void Start()
{
StartCoroutine(Move());
}
private void FixedUpdate()
{
//rb.velocity = new Vector2(1f, 0); //This works
Debug.Log("Update: " + rb.velocity);
}
IEnumerator Move()
{
while (true)
{
yield return new WaitForFixedUpdate();
rb.velocity = new Vector2(1f, 0); //This doesn't work
//rb.MovePosition(transform.position + (new Vector3(1f, 0) * Time.fixedDeltaTime)); //This doesn't work
Debug.Log("Coroutine: " + rb.velocity);
}
}
}
gameobject.png
(100.3 kB)
Comment