Hello, I’m working on a 2D platformer and have recently begun implementing special slope movement where the player speeds up while going downhill like in Sonic. The way I’ve written the code right now though, this only works for slopes that go right, and slopes that go left will slow the player down even though they move downwards. I figure if I can detect whether the slope goes left or right I could use an if statement and switch the += acceleration to a -= acceleration, but I’m not sure how to do that.
You just implemented the solution I described, so you should really mark my post.
Besides, you coded it in a redundant, pedestrian way. Your variable names are poorly chosen. a and b mean nothing and _left_or_right is confusing and doesn’t clearly signify the purpose of the variable. Remember that the results of boolean expressions can be assigned to boolean variables. The whole thing can be done in one line of code: