- Home /
LookAt() Error
Hi,
I have a strange error, since I dont get what I am doing wrong. I have this code:
public Transform target:
void LateUpdate()
{
transform.LookAt(target);
}
So my object should look at a given target. When I move the gameobject, to which this code is attached I get the following errors:
Assertion failed on expression: 'IsNormalized(dir)'
Assertion failed on expression: 'IsNormalized(ray.GetDirection())'
Does anyone know how to fix this? Since I cant move my gameobject and looking at another object at the same time.
Thanks
I have tried your above code, include the situation of which the LookAt object and the target object in the same position, but I didn't get the error you get. Did you have other code which causes the error?
did you move this object via "hand" in transform and with transform.position(somewhere)?
And Both times no error occured? I thought of an Unity Version error, but I have the latest Version (of course still possible). Since I dont have any other Scripts attached to this object I dont know where the problem comes from.
The error happens after some time maybe 10 seconds, if your try it for the first time, after starting unity new, afterwards it occures instantly
Answer by FlaSh-G · Sep 06, 2017 at 10:52 AM
Sounds like the target is at the exact same position as the object supposed to look at it. Maybe it's even the very same object.
Thanks for your suggestion, I checked that possibility and I dont think that it occurs in my situation.
I fixed it with, RotateTowards() ins$$anonymous$$d of LookAt(), I dont know why, but the eror didnt occure there