Character accelerates while running towards walls. "Sonic effect"

Hi everyone,

Imagine if your game was 2.5D, and you couldn’t rely on force physics for everything, since your models are 2D sprites encased in invisible spheres and cubes. Some of the game’s physics must be coded by yourself or it looks unrealistic (the sprites are flat, and any tilting or movement on the invisible cubes or spheres that contain them creates a weird effect).

Now imagine if you’re playing a car/racing game. You hit a lamp post on the track and keep accelerating, pushing towards it. The lamp post isn’t destructible, so your car doesn’t move. However, acceleration in the movement axis is still taken into account, and as soon as you slide off from the lamp post, you get shot forward unrealistically at high speeds:

74918-car-and-obstacle.png

These two things create an impossible combination for me: I have to manually assign velocity to the character based off the Axis acceleration, so every time the character gets stuck in an obstacle, he can slide off and max speed for an unrealistic effect. I call this the “Sonic effect”, because it works similar to when Sonic charges up his spin-dash and then gets shot forward.

To solve this, I’ve tried many things, but the only sensible solution is detecting which of the 4 sides of the object the character is colliding with, and annul all axis acceleration towards that place.

The problem is that I can’t make 4 colliders for an item without them being treated as a compound collider, and detected as if they were only 1 collider

… Or can I?

Does anybody know a solution to this? I can’t believe I’m the first with this problem, but I’ve been looking for questions like this one and I can’t find any.

Thanks in advance!

Well, probably I’m a bit too late -like 4 years- but I seriously couldn’t find any answers for a similar issue. And this is a core thing for acceleration. I don’t know if you already found an answer or not, but I’m writing to let other people know, since this is one of the first posts I encounter when searching the topic.


Anyway, so in my case I had a simple platformer controller that can accelerate. It moved with rigidbody.velocity and it had acceleration and deceleration values. There were 2 issues. 1)Whenever I hit a wall, the player keeps decelerating. 2)When I keep pressing the movement key and jump on top of the wall, I get launched with max acceleration.


The way I handled the first issue was, when my character hits a wall, the rigidbody.velocity’s x axis equalled zero. Which means, if I checked if rb.velocity.x == 0, I could reset my player’s deceleration value so whenever I stop, I don’t decelerate anymore, which totally makes sense in any situation.


I also had a moveSpeed variable, which slowly equalled to a maxSpeed value. I achieved this with Mathf.SmoothDamp, smoothing the value over the acceleration and deceleration values depending on which key has been pressed. So for the second issue, I made something quite similar. I just set the moveSpeed value (NOT MAX SPEED) to 0 when rb.velocity.x was 0. Which again made sense because when not moving, the player can surely have no speed.


As far as I understood from what you have written above, the car gets a full stop when hitting a lamp post. So setting moveSpeed to 0 should hopefully help out. Regards.