im trying to make a script that allow my camera moving into 4 differents position ( front back left right ) using keyArrows and lerp.
the first movement works good, but when i hit another KeyArrow my camera move a little bit and get stucks between the first position and the end position.
There is the code :
void Update()
{
if (Input.GetKey(KeyCode.UpArrow)){
Uparr = true;
}
if (Input.GetKey(KeyCode.DownArrow)){
DownAarr= true;
}
if (Input.GetKey(KeyCode.RightArrow)){
Rightarr = true;
}
if (Input.GetKey(KeyCode.LeftArrow)){
Leftarr = true;
}
//boolean
if(Uparr){
cam.transform.LookAt(target);
cam.transform.position = Vector3.Lerp(StartPos.position,endPosition1.position,lerpSpeed*Time.deltaTime);
if (cam.transform.position == endPosition1.position){
Uparr = false;
}
}
if(DownAarr){
cam.transform.LookAt(target);
cam.transform.position = Vector3.Lerp(StartPos.position,endPosition2.position,lerpSpeed*Time.deltaTime);
if (cam.transform.position == endPosition2.position){
DownAarr = false;
}
}
if(Rightarr){
cam.transform.LookAt(target);
cam.transform.position = Vector3.Lerp(StartPos.position,endPosition3.position,lerpSpeed*Time.deltaTime);
if (cam.transform.position == endPosition3.position){
Rightarr = false;
}
}
if (Leftarr){
cam.transform.LookAt(target);
cam.transform.position = Vector3.Lerp(StartPos.position,endPosition4.position,lerpSpeed*Time.deltaTime);
if (cam.transform.position == endPosition4.position){
Leftarr = false;
}
}
do you know what it can be the problem ?