Update:
One problem was that the velocity was only being updated once when the collision first happened, then was being overriden by FixedUpdate. I've fixed that, and a few other errors that popped up, but there is one other:
Here's my new code:
void FixedUpdate()
{
float moveHorizontal = Input.GetAxisRaw("Horizontal");
float moveVertical = Input.GetAxisRaw("Vertical");
Movement = new Vector2(moveHorizontal, moveVertical);
Movement.Normalize();
rigidbody2D.velocity = Movement * Speed;
if (Colliding && Movement == RecordMovement)
{
rigidbody2D.velocity -= Normal * Vector2.Dot(rigidbody2D.velocity, Normal);
}
else
{
RecordMovement = Movement;
}
}
void OnCollisionEnter2D(Collision2D other)
{
Normal = other.contacts[other.contacts.Length - 1].normal;
Normal.Normalize();
OppositeNormal = Normal * -1;
if ((OppositeNormal != Movement) && (Colliding != true))
{
Colliding = true;
}
else
{
Colliding = false;
}
}
void OnCollisionExit2D(Collision2D other)
{
Colliding = false;
}
However, then I had another problem. Well, several other problems. I've resolved some, but one remains.
If I am up against a wall, and moving parellel to it so that my collider is 'just touching' the wall, and I hit a diagonal from there, then I move just as slow as if my new code didn't exist. After lots of debugging, I found that we are detecting a new collision, but if I try to get the normal of this new collision, I end up with the normal of the old collision (the wall I was sliding against) I don't know if this is a bug in Unity, or a flaw in the colliders generated by the 2D tilemap, or what.
I even tried changing my code to "Normal = other.contacts[other.contacts.Length - 1].normal;", assuming that would get the last element of the array (latest), but no dice, same incorrect normal.
So, any ideas?