- Home /
hi, how to make topdown 2d lerp rotation on turret??. i.e. turret smoothly rotates on target.basic code below:
current corny setup :
void Update () {
float dist = Vector2.Distance (gameObject.transform.position, target.transform.position);
if (dist < 12) {
transform.LookAt (target.transform.position);
transform.Rotate (new Vector3 (0, -90, 0), Space.Self);
}
}
Comment
Answer by MarksGames · Apr 20, 2018 at 08:23 PM
Use Vector3.Lerp to linearly interpolate between your current vector and the target vector, you can store the output of transform.LookAt in a Vector3 and plug it into the Lerp function to get a smooth output.
yes i understand ,just not sure how to write the code for it..
would you help me with the code please? still i cant seem to wrap my head around it , thanks a bunch :))