I have a character menu and when I select my character and load my level my smooth follow will only follow one of the four characters. How do i fix this please help.
There are plenty of scripts like this floating around the web, and we can’t give you the code straight away, but I’ll try to explain it…
//Initialize all the targets in the scripts inspector
public Transform[] targets;
//select a target from the array above
public int targetToMoveTo = 0;
//your current transform
private Transform myTransform;
//the smoothing for moving the camera towads a target
public float smooth = 4;
void Start ()
{
//its less performance consuming to put the transform in a variable and use this, instead of calling it straight away each frame
myTransform = transform;
}
void Update ()
{
MoveTowardsTarget(targetToMoveTo);
}
void MoveTowardsTarget(int target)
{
//the magic
Vector3.Lerp(myTransform.position, targets_.position, smooth * Time.deltaTime);_
}
Now if you want to follow all of the characters (or that’s what I think you mean…) you should do some basic math somewhere with the target positions, which woulnd be hard if you have basic script knowledge.
GL
[1]: Unity - Scripting API: