- Home /
Smooth 2D collisions / colliders pushbacks
Problem: I am currently making a 2D rts game, and I want to make a smooth collision system between friendly units. Currently, I have a script controlling the colliders of my units, enabling it whenever it stops moving, and disabling it when it starts moving. The problem with this is, whenever two friendly units goes to the same position or when the colliders intersects, when both the colliders are enabled, they instantly teleport away from each other, as in their colliders pushed each other away instantly. The effect I want is kind of like StarCraft 2 (Game by blizzard), where you can have units go to the same position, however, when they stop moving, every unit slowly pushes each other away smoothly instead of instant teleport.
My current direction is to use a trigger collider, and when they stopped moving, if there is another overlapping collider, calculate the opposition direction of the collision point, and then use a rigidbody function to slowly push the units away from each other. However, I don't know how to calculate this and have no idea how to implement this.
I appreciate any suggestions/help thank you.