2D Constant Speed Movement

Hey all,

Fairly new to unity and I’m just curious as to how you guys wold deal with this issue. I have got an enemy in my top down shooter which locates the player then flies at high speed towards them. As there are box colliders within the level, this enemy needs to be able to hit a collider and stop.

Using either transform.position = Vector3.MoveTowards() or RigidBody2D.AddForce() causes the enemy to get stuck within the box colliders of the walls of the level. This only occurs on the TOP of the box collider however, the two sides and the bottom surface rarely experience cause such an issue. I was wondering what you guys might think it is. This does not occur with my player object.

I use the tag “Walls” and “Enemy” on these object respectively. Raycasts from the enemy when it is stuck report “Walls” or “Enemy”, rather than “Player” as it should (when in range). I can physically move the enemy out of its position and it will begin functioning normally again.

The walls are static rigidbodies with a simple material.

Maybe try Composite Collider 2d? Unity - Manual: Composite Collider 2D
Is the stuck player/enemy using a CapsuleCollider2d? Unity - Manual: Capsule Collider 2D

CompositeColliders remove the very tiny bumps on which someone can get snagged. The roundness of the capsule helps reduce the chance further.