Hey so when my player runs up to a door, the player stops, but when my player opens the door, which I have made it so the door box collider .trigger = true now (so the player can go through the open door), the player has a change in x velocity very quickly, causing the running animation to play for about half a second. This bug is really frustrating because I have checked OnCollisionExit2D which is called when the door opens since it’s .trigger is true now and my player’s rigidbody 2ds velocity x is = 4.something, when it should be zero so the idle animation will continue playing.
Only a handful of things affect velocity: Your script or internal collisions and gravity. Changing a collider to be a trigger won’t change the velocity.
You have something else going on here, I cannot tell you what that is.
Yes you were right, there was something else going on. By commenting out code I got to the line that causes the issue which is setting the transform.position of the door to the right by an offset when the door opens to the right. When this is commented out, the player doesn’t have this ‘velocity change’ or bug, however, I’m still confused because this shouldn’t change the velocity of my player since I changed the collider to is trigger just before this code, so it should have no collision interaction with the player to change it’s velocity…
You should never modify the transform when using 2D physics, that’s the role of the Rigidbody2D (to write to the Transform). That in of itself doesn’t change velocity so it’s unclear what side-effect is causing that but if you change the position to a point of overlap then the solver will be forced to resolve that overlap but, as you say, if it’s a trigger then as you change that property, all contacts will be removed there and then and next time the solver runs it’ll have no collision response so again, something else is causing this.
Has to be either collisions or something in a script modifying it directly or indirectly.