PDA

View Full Version : Getting the position of an object on a path


Enivob
04-11-2003, 03:34 PM
Hi,

I have a max script that does camera cuts. Basicaly you put a bunch of camera in the scene, then run the script and it makes a new camera that cuts between all the others. I want to enhance this so it can cut between animated cameras, this is where I am running into problems.

I am trying to get the position of an object that has its position derived from a path position controller.

I assumed that I could simply "poll" the object at any given frame to get the position of the object on the path at that frame. But this is not working, I always get the same value no matter what frame I move to before I "poll" the object.

Here is some code... perhaps someone can see my obvious mistake.

obj_array = $* as array
s=0
frameCount = animationrange.end
frameStep = frameCount / objCount

--Create the camera and the target for the camera.
camTarget = targetobject position:[0,0,10]
newCamera = targetcamera pos:[0,0,0] target:camTarget name:"CutCam"
newCamera.target.name = newCamera.name + ".Target"

-- Create and assign new controller.
ctrl = bezier_position ()
newCamera.pos.controller = ctrl
trgt = bezier_position ()
newCamera.target.pos.controller = trgt

for obj in obj_array do
(
result = case superclassof obj of
(
Camera:
(
-- Animate the camera.
for n = s to (s + frameStep) do
(
at time n
k = addNewKey ctrl n
-- Here is the problem line, even though I am at frame N, the obj pos is always the same.
k.value = obj.pos
)
s=s+frameStep
)
)
)

Thanks,

Enivob

Enivob
04-11-2003, 05:12 PM
I guess I'll answer my own thread again.

The problem was my misunderstanding of the "at time" function.

It works like a loop, you have to place all lines of code that you want affected inside parenthesis like so.

at time
(
k = addNewKey ctrl n
k.value = obj.pos
)


Swami helped me out!
Long live the code warrior.

CGTalk Moderation
01-14-2006, 07:00 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.