- Home /
Trying to get turret (or simple cube) to turn toward player
Trying to follow tutorials and online manual to use LookAt to make a turret (or a simple cube for starters) rotate around to face my player / FirstPersonController.
Here's the very simple script I'm using,
var lookAtTarget: Transform;
function Update () { transform.LookAt(lookAtTarget); }
I've seen some better ways mentioned on other threads, but I'd like to get this very simple one working first before moving on to more advanced methods. I've added this script to my turret's body without luck, and tried with a simple gameObject cube as well. Both times I selected FirstPersonController as my target for the script.
Any suggestions? Not getting any movement/rotation at all as my player walks around the object.
Thanks
This is very odd, filed a bug? You could also grab the sentry gun script from the fps tut and edit that...
@Fishman92: filing bugs should only be done for actual bugs in Unity, it's not a help center.
Answer by Statement · Dec 23, 2010 at 11:25 PM
It seems you must have overlooked something very basic.
- Create a new scene.
- Create a cube.
- Create a sphere.
- Put the script on the cube and let Look At Target reference the sphere.
- Run the game through the editor.
- In real time - In scene view, try moving the sphere around. The cube should look at the sphere.
If this works, then your script work. You might have other problems such as:
- Your object that should look at the player might have other scripts overriding rotation.
- You haven't properly referenced the player transform. Make sure you really referenced the part that moves around, not some root node that is static.
- Make sure your script is enabled (however it is enabled by default).
- While the game is running in the editor, pause the game and make sure that your reference is set.
Thanks for the recommendation. I'm reasonably techie but don't have a program$$anonymous$$g background so I often forget to return to or start with the basics to isolate a problem. Problem this time was after setting up my target I wasn't hitting apply, thus wasn't storing the change.
Will try using a couple of empty game objects next to reorient my turret which seems to be oriented the wrong way.
I find myself reasonably techy and have a program$$anonymous$$g background but I often find myself making simple/stupid errors all the time. Relax, it happens all the time. Often asking a simple question can solve a long debugging question due to something obvious