- Home /
Lerp problem
Hi I have a snippet of code wherein a target goes to mouse position and another object looks at it.
if(Input.GetMouseButton(0)){
var temp = Input.mousePosition;
var New = Camera.main.ScreenToWorldPoint(temp);
}
Target.transform.position = Vector3.Lerp(Target.transform.position, Vector3(New.x,New.y,0), 1);
ThisTransform.rotation = Quaternion.LookRotation(Target.position);
If I do it like that, the target will pop to the center of the screen after a second or so. What causes the target to go to the center? If I put the Lerp in the if statement it doesn't pop back to the center. What am I missing?
Answer by fafase · Nov 30, 2012 at 09:04 AM
Yep check this one:http://unitygems.com/mistakes1/ Find the How to move with Vector3.Lerp section.
Your issue is the 1 as ratio parameter. It means full move at once.
No that's not the issue. I have it on 1 for testing purposes. And it does move at once, which is fine for now, but after the movement is complete, the target that moves just goes to the center of the screen.
Nope, nothing outside of this script is manipulating Target, it doesn't have a rigidbody or collider attached to it and the only recurring code snippet for Target is when I declare it in Start().
I have found that the variable New goes back to 0,0,0 at that time.