Let's go over what your code is doing, and perhaps we can point some things out.
You use the variable Movement
to capture the input for each axis at each update frame:
void Update()
{
Movement.x = Input.GetAxisRaw("Horizontal");
Movement.y = Input.GetAxisRaw("Vertical");
}
Capturing this in a Vector2
makes sense since you're moving in 2d, and doing it in the Update
callback makes sense since you want to read the input every frame. So far so good.
Then in fixed update, you're moving the position of the Rigidbody2d
by doing so:
rb.MovePosition(rb.position + (Movement * Movementspeed * Time.fixedDeltaTime));
What is the value of the variable Movementspeed
at this point? Unless you have used the property setter to give it a value from somewhere else, it would default to (0,0). So the value of the statement (Movement * Movementspeed * Time.fixedDeltaTime)
will return 0. So essentially you're setting the position of the rigidbody to its current position.
But really think about what you're trying to do in that statement. Movement
is a 2d vector that represents your direction of movement, Time.fixedDeltaTime
ensures that we move by a consistent amount no matter the variance in time between fixed update calls, but what is the purpose of Movementspeed
? You're doing a cross product here when I don't think you intend to. You don't really need to use another Vector2
to represent your speed, just use a float. Remember that any vector multiplied by a float just changes the magnitude of that vector. The direction stays the same.
So what you probably want to do here is:
rb.MovePosition(rb.position + (Movement * moveSpeed* Time.fixedDeltaTime));
where moveSpeed
is the float variable you've defined at the top of the script.
MovementSpeed
ever assigned a value? The default fornew Vector2()
would haveX = 0, Y = 0
soMovement * (0) * Time.fixedDeltaTime = 0
. \$\endgroup\$