LookAt how to define which direction the prefab is looking at?

Hey People,

Hope someone can help with the Realm Rush course.

The prefab I’m using is following the path, and turning, as it should be (using the LookAt function). However, the prefab always faces the wrong way, how do I assign what is the front of the prefab and what is back? I’ve tried modifying the prefab using rotation, also rotating when placed in the scene, but it always rotates and walks backwards.

Thanks.

Hi,

Welcome to our community! :slight_smile:

The prefab has got a child game object, doesn’t it? If that child contains the mesh, you could simply rotate the child relative to the parent. When the parent rotates, the child rotates along with it automatically.

Hi Nina,

Thanks for the reply. The parent, and all children, had mesh renderers on them. I’ve literally had to create an entirely new prefab to get it to work, but got there in the end.

Many thanks,

Just as a little side note, which made me understand LookAt() and rotation methods much better, specially those that move the Forward vector. The Forward vector is intrinsic to every game object and it is the Z (blue) vector in the local rotation coordinates of the specific game object and (I think) can’t be changed inside Unity (but may be changed to meshes in 3D modelling software like Blender or Maya probably) so the best course of action is what you did, nesting gameobjects in hierarchy and rotating a parent or child that is looking in the direction that you need.

To check what the forward vector is for a specific game object, you can click the button above the editor window that is right next to a little magnet in a grid to change between World Units to Local Units. I think the hotkey for it is ‘H’.

That’s great, thanks for the info.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms