Collider2D disabling movement

I have everything working fine on a 2D td game, where enemy sprites use pathfinding to go after characters in the character party when they are in range.

I have the usual components, the Pathfinder for the graphs (grid), then AIPath, plus its modifiers and also AIDestinationSetter, which I’m setting via script for closest target. Collisions in the graph are set to point.

I have a RigidBody2D attached to players and enemies for handling physics and object interaction.

I’m using aiPath.desiredVelocity for setting the sprite’s animation direction on moving and attacking.

But whenever I add a collider2D of any kind to my enemy object, movement is being disabled. I only need it for enemy/player interactions, so that they don’t walk through each other.

I’ve been hunting around and hoping that as I get familiar with A* Pathfinding Project that I’d figure it out. I’ve created a workaround for setting spriteRenderer sorting layers so that although I cannot use collisions to keep some separation between enemy and player character, they at least appear correctly in the space (behind and in front of) relative to their positions when interacting.

But I’d really love to figure out why the Collider2D is disabling the pathdfinding. (I’ve even tried putting the collider on a child object, trying different colliders, but it still disables movement). Any thoughts?

I’m still stuck with this. And now I’m having serious problems setting up my attack functions, because obviously it relies on colliders.

Anyone got any thoughts one why adding a simple collider to the root or child object disables the pathfinding chase? canMove remains on. If I disable the collider, the character starts to move.

I’m sure this isn’t normal, but I’ve followed all the normal setup.

Hi

I’m not sure why a collider would disable movement… It shouldn’t… Try to make/unmake the rigidbody to be kinematic.

Also. To get agents to collide with each other I would recommend using local avoidance instead of colliders. Colliders typically don’t get you very smooth results. See Local Avoidance - A* Pathfinding Project

Thanks Aron. I think something in my controller script was interfering with the rigid body. I’ve switched to a different approach and it’s working now. I’ll look into local avoidance. Thanks for that.

1 Like