x


Camera rotating around rolling rigidbody sphere

I have a camera linked to a rigidbody sphere parent that's rolling down a spiralling tunnel. The camera is presently rotating wildly (because the rigidbody sphere is) - what script(s) could I use to make the camera ignore the local rigidbody rotation down the spiral? I don't want to control the camera or sphere by mouse or keyboard input.

more ▼

asked Mar 10 '10 at 12:37 AM

Squirrel gravatar image

Squirrel
5 2 2 7

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

2 answers: sort voted first

Connect the camera to a new GameObject and add to this gameobject a script with:

var follow : Transform;

function LateUpdate() {
    transform.position = follow.position;
}

next, in inspector of the gameobject, set follow to the rolling rigidbody instance (just drag it from scene view to this property).

more ▼

answered Mar 10 '10 at 03:29 AM

Jaap Kreijkamp gravatar image

Jaap Kreijkamp
6.4k 20 26 70

Thanks, Jaap - exactly what I needed, that technique of using a 'middleman' invisible gameobject to do the follow is half the solution :-) Why is LateUpdate used rather than Update?

Mar 10 '10 at 07:44 PM Squirrel

doesn't matter much, but the lateupdate makes that you're certain the position of the object to track is already updated so you don't get lag/jitter in camera.

Mar 11 '10 at 03:33 AM Jaap Kreijkamp
(comments are locked)
10|3000 characters needed characters left

that "Empty GameObject Trick" is like this..

var targ:Transform;
var offset:Vector3;
function Start(){
offset=transform.position-targ.position;//init offset at start
}
function Update(){
transform.position=targ.position+offset;
}
more ▼

answered Aug 19 '11 at 03:19 AM

Techsuport gravatar image

Techsuport
81 6 6 10

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

x3002
x2166
x1792

asked: Mar 10 '10 at 12:37 AM

Seen: 2711 times

Last Updated: Aug 19 '11 at 03:19 AM