I’m following this tutorial and ran into something I wasn’t sure of the answer to.
void Move (float h, float v)
{
// Set the movement vector based on the axis input.
movement.Set (h, 0f, v);
// Normalise the movement vector and make it proportional to the speed per second.
movement = movement.normalized * speed * Time.deltaTime;
// Move the player to it's current position plus the movement.
playerRigidbody.MovePosition (transform.position + movement);
}
In the example, the RigidBody is a child component of the player prefab. Does RigidBody.MovePosition update the parent object transform as well? It doesn’t state it as such in the documention, but I was really confused as to how I was moving the parent when it felt like I was only moving the RigidBody.
I noticed if I just wrote “this.transform.position += movement;” I got seemingly identitical effects, presumably because I moved the parent object and the RigidBody had to move with it? What’s the difference between setting transform.position and RigidBody.MovePosition()?
TL;DR: How does moving a child object move the parent? I assume RigidBody.MovePosition must update the parent object transform?
BONUS: What’s the difference between setting transform.position and RigidBody.MovePosition()?
Thanks!