PDA

View Full Version : Orbit camera around target


davgothic
02-10-2010, 04:11 PM
Hi!

I'm having trouble writing a script that can make a target camera orbit it's target at a set distance and add keyframes at every 10degree increment.

Here is the process the script should create:



Place camera above target at around 600mm away
rotate camera through 360 degrees and add a keyframe at every 10 degree increment
drop camera by 10 degrees and repeat step 2 till camera is at very bottom of target




Here is the code I have so far, it just doesn't seem to work as expected.



When the camera is at the top it sits there stationary for 36 frames.


cam = TargetCamera target:(targetObject pos:[0,0,0]) pos:[0,0,600];

fn rotateCamera hAngle vAngle = (
hAngle = (90 - hAngle);

x = cam.Target.pos[1] + (cos(hAngle) * sin(vAngle) * cam.targetDistance);
y = cam.Target.pos[2] + (sin(hAngle) * sin(vAngle) * cam.targetDistance);
z = cam.Target.pos[3] + (cos(vAngle) * cam.targetDistance);

return [x,y,z];
)

count = 0;

for v = 0 to 180 by 10 do (

for h = 0 to 350 by 10 do (

at time count animate on cam.pos = rotateCamera (350 - h) v;
count = count + 1;

)

)


Could anybody tell me where I am going wrong? Or point me in the direction of an easier way of doing this?

Thanks in advance!

JHaywood
02-10-2010, 04:37 PM
Look up the 'about' context in the help file. That let's you specify rotations, or whatever, 'about' another object or position.

davgothic
02-10-2010, 04:53 PM
Thanks for your reply. I had a play with "about" before, although I got the camera to rotate around the target exactly how I wanted it, the top of the camera doesn't always point "north".

Sorry if that doesn't make much sense.

CGTalk Moderation
02-10-2010, 04:53 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.