x


Make a light follow a first person controller

Hi I am just starting out in unity so I will appologise if this has been asked before, I have searched but cannot find a post that helps. How do I make a direction light follow a first person controller. I presume that you add a script to the light object and then target it to the FPS object. I trird the following with no sucess my FPS object is called "Bod".

function Update () { GameObject.Find("Bod").GetComponent("SmoothFollow");

}

I just want the scene to light in the direction the FPS controler is facing.

more ▼

asked Aug 28 '11 at 03:12 PM

WingChunManiac gravatar image

WingChunManiac
1 1 1 1

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

Yours is not the best way to do it, although it's theoretically possible. The proper way would be to set the light to be a child of the camera (which should in turn be a child of the whole fps controller thing) and make it face the same way in edit mode. Then, when the camera rotates, the light will rotate with it. This will make the light follow every movement of the camera without delay.

more ▼

answered Aug 28 '11 at 03:30 PM

Arshia001 gravatar image

Arshia001
91 11 12 14

(comments are locked)
10|3000 characters needed characters left

You can just make the directional light a child of the first person controller, then it will follow it around in the direction that you are facing on the x and z axis. However if you want the light to follow the mouse in other planes then you'll need to write a function.

more ▼

answered Sep 08 '12 at 04:25 PM

lilroo gravatar image

lilroo
16 1

(comments are locked)
10|3000 characters needed characters left

Thanks I thought there would be a simpler way to do this. The only problem is if I add the light to the built in FPS Prefab it breaks it. I presume to do this I will need to create a new FPS prefab with the light included.

more ▼

answered Aug 28 '11 at 04:30 PM

WingChunManiac gravatar image

WingChunManiac
1 1 1 1

Well, technically that shouldn't happen. How exactly does the light "break" the controller? Out of curiosity, are you gonna put a flashlight on your character? You'd need a projector for that, not just a light source.

Aug 29 '11 at 03:46 PM Arshia001
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x425

asked: Aug 28 '11 at 03:12 PM

Seen: 1324 times

Last Updated: Sep 08 '12 at 04:25 PM