Are I stupid? Vector3
Hi guys. I has the problem with this (script for example):
public bool thisBool;
public Transform gameCamera;
public Vector3 CameraCrouchedPos = new Vector3(0.00f, 0.1f, 0.00f);
public Vector3 CameraStayingPos = new Vector3(0.00f, 0.82f, 0.00f);
void Update ()
{
if(Input.GetKeyDown("g"))
{
thisBool= !thisBool;
print("thisBool was changed");
}
if(thisBool == true)
{
gameCamera.position = Vector3.Lerp(CameraStayingPos, CameraCrouchedPos, Time.deltaTime);
print("changed");
}
When I press key (g) camera change position to crazy values. When it need to be on 0,0.1,0 it is on 13.3457,2.31,-7.671234. I really don't understand how this works. How I can fix that?
Answer by tormentoarmagedoom · Jun 12, 2018 at 10:03 AM
Good day.
I think you are using wrong the Lerp function. Lerp function interpolates between 2 position, with a parameter called "t" . But "t" is not time, is just a number from 0 to 1 to know where to interpolate. Lets make an example, if i want to interpolate a Vector3 position from 0,0,0 to 0,0,100. The "t" parameters says "how much away from intial will be the result"
Vector3 initial = (0,0,0);
Vector3 final = (0,0,100);
if "t" is 0.5
Vector3 newposition= Vector3.Lerp ( initial, final, 0.5f);
Newposition will be (0,0,50);
if "t" is 0.9
Vector3 newposition= Vector3.Lerp ( initial, final, 0.9f);
Newposition will be (0,0,90);
And if "t" is 0.1, result will be (0,0,10)
So, if "t" is 0, the result will be the initial position.
And if "t" is 1, result will be final position
Understand? So, using Time,deltatime, have no sense!!
Bye :D
Your answer
Follow this Question
Related Questions
Question about Vector creation 1 Answer
I need help with the location of instatiated objects on the scene and correct interaction with this 0 Answers
Player Floating 0 Answers
gameobject position lerp 0 Answers