Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+5 votes

Anyone know how to implement it where the enemy won't get right on top of my player and will stay a little bit away at least so then it won't get stuck into my player?

asked in CSC380Jan2024 by (2k points)

3 Answers

+3 votes

Try adding a Collision2D box that is bigger than the enemy’s hurtbox. Set the mask to only collide with the player. That should keep the enemy the desired distance away from the player.

answered by (562 points)
+2 votes

If you implemented the path-finding algorithm to your enemy you usually run into this problem because your enemy just keeps trying to make it to your player position, you could change the target position to be slightly off from the player's actual position to allow for a gap between player and ene,y.

answered by (2k points)
0 votes

To keep the enemy character from getting too close to your player, you need to add a bit of code that checks how close the enemy is to the player. If the enemy gets too close, closer than a distance you decide is just right, the code should make the enemy either stop or back away.

answered by (1.1k points)
...