I’ve tried searching for an answer to this and come up with nothing. My player movement was working fine until I made a bunch of changes to my game and went back to check on things, and now my player will not move at all. Animations are working fine, and when I use debug.log it shows the rigidbody velocity I would expect, but the player is stuck in one place, and when I try to move it manually in the inspector while I’m in play mode, it doesn’t move, either. My rigidbody is set as Dynamic.
Here’s the relevant code:
void Update()
{
playerMoving = false;
if (moveDirection.x > 0.5f || moveDirection.x < -0.5f)
{
myRigidBody.velocity = new Vector2(moveDirection.x * moveSpeed, 0f);
playerMoving = true;
lastMove = new Vector2(moveDirection.x, 0f);
anim.SetFloat("MoveX", moveDirection.x);
anim.SetFloat("MoveY", 0f);
}
if (moveDirection.y > 0.5f || moveDirection.y < -0.5f)
{
myRigidBody.velocity = new Vector2(0f, moveDirection.y * moveSpeed);
playerMoving = true;
lastMove = new Vector2(0f, moveDirection.y);
anim.SetFloat("MoveX", 0f);
anim.SetFloat("MoveY", moveDirection.y);
}
if (moveDirection.x < 0.5f && moveDirection.x > -0.5f)
{
myRigidBody.velocity = new Vector2(0f, myRigidBody.velocity.y);
}
if (moveDirection.y < 0.5f && moveDirection.y > -0.5f)
{
myRigidBody.velocity = new Vector2(myRigidBody.velocity.x, 0f);
}
anim.SetBool("Moving", playerMoving);
anim.SetFloat("LastMoveX", lastMove.x);
anim.SetFloat("LastMoveY", lastMove.y);
lastMoveVec3 = new Vector3(lastMove.x, lastMove.y, 1f);
}