x


Camera Focus on Object

I have an object which is moving around on the plane, I want that, if object move in some direction, camera also move with object. Please guide me how can I do this.

Sorry for my bad english

more ▼

asked Dec 27 '10 at 11:18 AM

Arman gravatar image

Arman
13 3 3 10

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

2 answers: sort voted first

The easiest way would probably be to make the camera a child of the object. If you move the object, the camera will move along.

If it's enough to only "focus" on the object as in 'looking at the object', try to use Transform.LookAt

more ▼

answered Dec 27 '10 at 11:25 AM

Sebas gravatar image

Sebas
4k 12 18 45

@Sebas, I have tried Transform.LookAt, but actually I want that camera moves with the object.

Dec 27 '10 at 11:41 AM Arman

In that case, the parent/child solution might be best and easiest. You could also apply any movement to camera and object individually, but it really depends what you need this functionality for.

Dec 28 '10 at 01:03 PM Sebas

What I do in this case is write a script that targets the transform of whatever I want the camera to look at. Then I rotate the camera at it and use a LERP to move it around to where I want. Something kinda like this

void lookTarget (Transform _lookTarget) { Quaternion lookAt = Quaternion.LookRotation(_lookTarget.position - transform.position); transform.rotation = Quaternion.Slerp(transform.rotation, lookAt, turnSpeed); transform.position = Vector3.Lerp(transform.position, _lookTarget.position + camOffset, targetMoveSpeed); }

Jul 23 '12 at 01:05 AM darthbator
(comments are locked)
10|3000 characters needed characters left

If i understand your ? right then you can use "Smooth follow" to make the camera follow a object when it moves.

Just search "Smooth follow" in the search bar in unity 3D and select "Smooth follow" and attatch it to the camera, and set the target to the object you want the camera to follow. Then when the object moves the camera konstantly looks at it.

more ▼

answered Dec 27 '10 at 11:30 AM

OrangeLightning gravatar image

OrangeLightning
5.4k 47 57 112

(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:

x5086
x3740
x2000

asked: Dec 27 '10 at 11:18 AM

Seen: 3968 times

Last Updated: Jul 23 '12 at 01:05 AM