x


following camera script

Hi there! I'd like to have a script for camera folowwing a gameobject which is found in this sctipt by tag. Well, I know how to find the GameObject, but I've no idea how to create a following camera with first-person view. Help, please! **I'm using C#, would be nice if you will also use it for the explanation :)

more ▼

asked Aug 28 '12 at 04:03 PM

arcadia gravatar image

arcadia
-4 2 2 3

Have you already looked at "Standard Assets/Scripts/Camera Scripts"?

Aug 28 '12 at 11:28 PM Sisso
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Awesome! So a bit more of an easy question to start. Usually in the Answers we won't just write your code for you. But I guess I'll be the exception. You don't have to have the actual object scripted to follow the player unless in 3rd person. You can just drag the Camera as a child to the object itself. But besides that here we go.

This will be the final player instance in which we will use. GameObject Target;

Now that we have created the variable for the final target we have to go ahead and define the target itself and apply the actual movement of the object.

void Start () {
   Target = GameObject.FindWithTag("YourTagName");
   transform.parent = Target.transform;
}

Thats really all that you need to do to apply a child. Is change Transform.parent to the parent transform. More info in the Unity Scripting Reference: http://docs.unity3d.com/Documentation/ScriptReference/Transform-parent.html

more ▼

answered Aug 29 '12 at 05:11 AM

Devon Hall gravatar image

Devon Hall
184 1 5

Thanks a lot! You really helped me!

Aug 29 '12 at 06:35 AM arcadia

Glad to know that I could help!

Aug 31 '12 at 01:27 AM Devon Hall

Also if this is the final answer you needed you can accept it as a final answer so people searching for similar questions can reference this as a complete question and answer.

Aug 31 '12 at 01:27 AM Devon Hall
(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:

x4147
x65

asked: Aug 28 '12 at 04:03 PM

Seen: 546 times

Last Updated: Aug 31 '12 at 01:27 AM