How do you get a character to follow you as an ally?

I need help. I need a dog to follow me, but he keeps circling. I tried a Box Collider but it didn’t work. I want him to stop when I stop, and move when I move. Is there a script for that?:face_with_spiral_eyes: I am using the FPS Prefab. I need the Dog to follow as a pet? Also, how can I assign an animation script, for example, if I am idle, I have the dog transformed into an idle animation, as well as walk and have a walk animation? FYI, I am using the First Person Controller

var target : Transform; //the canine’s target
var moveSpeed = 3; //move speed
var rotationSpeed = 3; //speed of turning

var myTransform : Transform; //current transform data of canine

function Awake()
{
myTransform = transform; //cache transform data for easy access/preformance
}

function Start()
{
target = GameObject.FindWithTag(“Player”).transform; //target the player

}

function Update () {
//rotate to look at the player
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);

//move towards the player
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;

}
I also am having trouble with the 101 010 button, don’t know where, what it is or how to use it. Thanks

There’s probably follower scripts out there. But you’ll need to find one that fits with your way of movement.

Here’s what you can do in your own method for basic following.

When ally isn’t near player, move towards player (straight line, resolve AI path, whatever).

When ally is near player, don’t move at all.

You can just do a distance test to see if the ally “near” the player.

Of course in time you’ll start creating decision trees. For instance, if enemy is near, you may choose to chase enemy instead of chase player. Then you might also add when ally is too far from player to not chase enemy anymore and to return back to player.

Would this help?1551365–90978–$Jolteon.js (737 Bytes)

Nobody’s going to just do it for you.

lordofduct already helped out a bit.

Also, the problem is that you’re turning and moving at once, but not taking into account the distance when you turn. You need to either turn faster or move slower as you get closer to your target. Otherwise, when you reach the point where the target is inside the turning circle it can never be reached because moving “forwards” is not actually moving you towards the target.