I have 2 3D rigidbody robots(aka cubes) with box colliders in my scene. Here is my script on one of them to follow the other (without rotation) and push it:
public class BotFollowSwerve : MonoBehaviour
{
public Transform target;
public float force = 10f;
private Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
Vector3 targetDirection = (target.position - transform.position).normalized;
rb.AddForce(targetDirection * force, ForceMode.Force);
}
}
The other robot is controlled by me (the player) and can rotate and move in the x and z axis. The issue is when i face the robot away from the follower robot, the follower just lines itself up about 2 robot lengths away with the player robot and starts vibrating in place. If i move the player robot without rotating it - the follower follows with it, but keeping its distance.

About assigning a wrong target position. I have a parent game empty game object that has the script and a rigidbody attached to it. A model with a box collider is inside the child for each of the robots. The target transform is just the player robots parent gameObject. I don't know if Rigidbody settings could possibly do this??
– MoMachine64Add a Debug.DrawLine in the following robot's FixedUpdate: Debug.DrawLine (rb.position, target.position, Color.red); The line will start at the robot to the target position
– ArachnidAnimalAlright I did that! It drew a semi long line when the robots are facing each other, showing that the follower is trying to push past, which is what it should be doing. When the follower is facing the back of my robot the line starts getting smaller and smaller as the AddForce starts jiggling back and forth. Something interesting to note though. The target.position line end is not at the origin of the player bot, its behind it a little ways. I have no idea why that would be. That is probably causing the issue though. Do you know what i could try? I added a picture of it to the main post.
– MoMachine64I put the model and its script inside a parent gameObject because the model had to be rotated 270 degrees in the x axis for it to be upright. So it messed up my movement script. I put inside a parent with a rotation of 0, 0, 0 to fix this issue.
– MoMachine64Ah, I solved it. It was about the gameObjects rotation. Apparently it has tons of issues if it was rotated manually in the prefab.
– MoMachine64