Hello
Im fairly new to scripting (and my english isn’t really good) and im trying to make my camera turn around my gameobject
I’ve almost manage to do it but everytime I hit the key to trigger the lerp the X axis of my rotation reset itself to 0 and i have no idea why.
Here’s part of my code
void Update () {
m_add90= Input.GetKeyDown(KeyCode.L)
m_Remove90 = Input.GetKeyDown (KeyCode.K);
if(m_add90){
OldAngle = new Vector3 (AngleInter.x, StartpointAngle.y, AngleInter.z);//this will get the Angle my camera is set to before the Quaternion.Lerp
TimeInter =0;//just reset the timer of the lerp to 0 everytime you hit the key to trigger the Lerp
Iterateur++;//that will be used in my switch case later
TimerIsOn =true;//Start the timer for my lerp
if (Iterateur == 5) {//I want my camera to go to 4 different position behind, in front and on each side of my gameobject
Iterateur = 1;
}
}
if (m_Remove90) {//same except that we decrement Iterateur
OldPosIni = new Vector3 (posX [0], gameObject.transform.position.y, posZ [0]);
OldAngle = new Vector3 (AngleInter.x, StartpointAngle.y, AngleInter.z);
TimeInter =0;
Iterateur--;
TimerIsOn = true;
if (Iterateur == 0) {
Iterateur = 4;
}
}
if (TimerIsOn) {//start my timer for my lerp
TimeInter += Time.deltaTime;
if (TimeInter >= 1) {
TimerIsOn = false;
}
}
switch(Iterateur){
case 1:
if (m_add90==true || m_Remove90==true) {
NextPosini = new Vector3 (Perso.transform.position.x, gameObject.transform.position.y,Perso.transform.position.z - 3); //I have another lerp that zoom the camera on my gameobject but its disable when TimerIsOn is true
NewAngle = new Vector3 (AngleInter.x, 0, AngleInter.z);//set the angle the camera should have at the end of the Quaternion.Lerp
}
gameObject.transform.rotation= Quaternion.Lerp(Quaternion.Euler(OldAngle),Quaternion.Euler(NewAngle),TimeInter)
StartpointAngle.y = 0;//will set the Angle for the other Quaternion.Lerp that I use to change the angle when we are zooming on the gameobject its disable when TimerIsOn is true
EndpointAngle.y = 0;//same this the angle the camera should have when the other Quaternion.Lerp is over its disable when TimerIsOn is true
gameObject.transform.position = Vector3.Lerp(OldPosIni,NextPosini,TimeInter);
/*this part doesn't matter
posX [0] = Perso.transform.position.x;
posX [1] = Perso.transform.position.x;
posZ [0] = Perso.transform.position.z-3
posZ [1]= Perso.transform.position.z-2*/
break;
//there's 3 other case which are pretty much copy and paste excepet for some values
if(TimerIsOn==false){
gameObject.transform.position = Vector3.Lerp(new Vector3(posX [0], posY [0], posZ [0]),new Vector3(posX [1], posY [1], posZ [1]),Temps);
gameObject.transform.rotation= Quaternion.Lerp(Quaternion.Euler(StartpointAngle),Quaternion.Euler(EndpointAngle),Temps);
AngleInter= new Vector3(gameObject.transform.rotation.x,gameObject.transform.rotation.y,gameObject.transform.rotation.z);//get the angle of my camera and should stop updating once the timer is on
}