Hi,
Maybe is a simple question, but, I’m trying a couple of things and unfortunatelly, in some of these, Unity closes.
I’m doing it to locate and position the object in the Waypoint.
var dj = GameObject.Find("Waypoint_"+WaypInicial);
myObj.transform.position=dj.transform.position;
So, my object is located correctly, but, I need to make the object look at the next Waypoint.
I have tried with the “transform.LookAt”, anyway, this don’t work, because the “next waypoint” are not a transform, is a GameObject.
(The waypoints aren’t rotated the way I need, because this I can’t use his rotation info, and, I have 4.000+ waypoints in each scene, so, is very hard to us to adjust each waypoint in the correct rotation).
Thank you.
Check out the scripting manual. GameObject has actually a property called transform:
transform.LookAt(myWaypoint.transform);
Thank you…
I forget to mention this, I’m already using the “transform.LookAt”…
But, Sometimes my cars are being created with 180º rotate on y axis… I have placed a code to rotate 180 after the LookAt, but, sometimes work, sometimes not.
dj = GameObject.Find("Waypoint_"+WaypInicial);
if (Direcao==1){
tdj = GameObject.Find("Waypoint_"+(WaypInicial-AddWayp));
}else{
tdj = GameObject.Find("Waypoint_"+(WaypInicial+AddWayp));
}
eu.transform.position=dj.transform.position;
eu.transform.LookAt(tdj.transform);
eu.transform.Rotate(0,180,0);
currentWaypoint=WaypInicial;
Sometimes I receive this message:
Quaternion To Matrix conversion failed because input Quaternio is invalid { 1.#QNAN0, 1.#QNAN0, 1.#QNAN0, 1.#QNAN0}
UnityEditor.Handles:Internal_DrawCamera(Camera,Int32)
The transform.LookAt function will fail if the target object is in the same location as the object that is looking (ie, there’s no way for it to know which direction it should look). Is this what is happening in your game?
I already get it working now andeeee.
The problems is that sometimes unity closes when I was trying to use the code I have posted before.
But now, I have created a New Car AI and are working OK.
Thank you.