I am trying to make a top-down action game, where enemies will use pathfinding to follow the player. My pathfinding system is based upon the one created by Sebastian Lague in his A* Pathfinding series: https://youtube.com/playlist?list=PLFt_AvWsXl0cq5Umv3pMC9SPnKjfp9eGW&si=0IackdURf8WNy9Fl
In order to move the enemies position to whichever waypoint is on the current path, the script uses this:
transform.position = Vector2.MoveTowards(transform.position, waypoints[index].position, speedMultiplier * speed * Time.fixedDeltaTime);
This works fine enough and hasn’t caused many issues for me.
However, I’ve been trying to implement a “conveyer belt” obstacle in my game, essentially it moves the player and any enemies on it either left or right. This currently works by using the Area Effector 2D
The issue is, changing the velocity of the gameobject through an Area effector and the rigidbody’s position in pathfinding seems to cause somewhat jerky movement.
In the image below, the character on the conveyer belt (the conveyer belt is the large black strip along the camera view) cannot move forward, and will only be able to lurch forward once the player’s position changes as it recalculates the path it needs to take. The character is not being pushed backwards while walking forwards, instead its just stuck in this one spot.
I’ve tried changing the speed, using a script that moves the transform instead of changing the velocity, etc. The player moves fine, but enemies consistently get caught on it.
Is there a better way of doing this? I don’t know how else to do it, and most results for “conveyer belts in Unity” are often related to big Factorio-style games or something; I just want an object that, when you or an enemy walks into it, can push you in a given direction without interrupting your scripted inputs.
