- Home /
Question by
TheBlackSenapi · May 18, 2019 at 06:21 AM ·
vrgamemodellookattarget
LookatTarget Script - Headtracking Player
I'm trying to use the LookatTarget script within unity on a humanoid model so the head turns and looks at the player and tracks when the player is within a certain range of the model.
Comment
Answer by Master-of-Games · May 18, 2019 at 06:42 AM
if(Vector.distance(target.transform.position, transform.position) < range)
{
Vector3 positionToLookAt = target.transform.position;
positionToLookAt = positionToLookAt - transform.position;
Quaternion lookRotaion = Quaternion.LookRotation(positionToLookAt, transform.up);
transform.localRotation = Quaternion.Lerp(transform.localRotation, lookRotaion, 0.2f);
}
I think this will work.
It doesn't. Something about the if statement isn't working. I get the compiler error "the name 'Vector' does not exist in the current context."
I just figured out what's wrong. Should be "Vector3.Distance" rather than "Vector.distance."
Your answer
![](https://koobas.hobune.stream/wayback/20220612201618im_/https://answers.unity.com/themes/thub/images/avi.jpg)