PDA

View Full Version : Scripted Controller Help, Acess own nodes pos?


Gibbz
01-12-2009, 06:42 AM
Im tyring to access the position of a camera target from the camera targets scripted controller but max will not let me do this.

Ive bolded the part thats bad. Ive tried using $.position. Is there a way to get the position of itself?


-- setup wireing for our target
mScriptController = position_script()
mScriptController.AddNode "mCamera" mCamera
mScriptController.AddConstant "mTargetSplinePoints" mTargetSplinePoints
mCamera.target.position.controller = mScriptController


-- this is a script stored in a string, START
-- 1. find closest target spline point
-- 2. use this scale/time to get the cameras spline point

mScriptController.script = "
mClosestDistance = distance mCamera.target.position mTargetSplinePoints[1][1]
"

xcise
01-12-2009, 09:11 AM
$.position will only work if the target is selected. don't know how your scene works, but you can try using the name of the camera like

$Camera01.target.position

ed: you can also use the name as the node...

Gibbz
01-12-2009, 09:35 AM
$.position will only work if the target is selected. don't know how your scene works, but you can try using the name of the camera like

$Camera01.target.position

ed: you can also use the name as the node...

$Camera01.target.position also gives the same error unfortunately. Ill try doing it a different way...

DaveWortley
01-12-2009, 11:09 AM
$Camera01.target.position works for me.

Silly question, is it actually a Targetted Camera or a Free Camera?

What error message are you getting?

Gravey
01-12-2009, 11:11 AM
i'm pretty sure what you are doing wont work because the script controller is the thing that is setting the position and you can't get the position without setting it first.
It's kind of like if you forget where you put something, and you no longer had the ability to search for it, then the only way you'd be able to find it is to know where it is, but you dont, so your screwed...

maybe if you'd like to share a bit more detail on what you're trying to do we could help with some alternative suggestions

PEN
01-12-2009, 01:40 PM
So what is the error that you are getting?

supremepizza
01-12-2009, 11:10 PM
Post your controller script.
The info you want should be in there.

Gibbz
01-12-2009, 11:30 PM
The error i get is "Illegal self reference in controller script"


ok ive got another idea to work around this storing values in the camera. Is there a way to read the constant values from a script controller?

For example i do
mCamera.position.controller.AddConstant myConstant

Is there a way to read this value?
ie mCamera.position.controller.GetConstant ?

Gibbz
01-12-2009, 11:30 PM
-- setup wireing for our target
mScriptController = position_script()
mScriptController.AddNode "mCamera" mCamera
mScriptController.AddConstant "mTargetSplinePoints" mTargetSplinePoints
mCamera.target.position.controller = mScriptController

-- this is a script stored in a string, START
-- 1. find closest target spline point
-- 2. use this scale/time to get the cameras spline point

mScriptController.script = "
mClosestDistance = distance mCamera.target.position mTargetSplinePoints[1][1]
mClosestTime = 1
mTimes=#()
mPosition = mTargetSplinePoints[1][1]

for i = 1 to mTargetSplinePoints.count do
(
mDist = distance mCamera.target.position mTargetSplinePoints[i][1]

if mDist < mClosestDistance do
(
mClosestDistance = mDist
mClosestTime = i
mPosition = mTargetSplinePoints[i][1]
)
)

mTimes[1] = mClosestTime
mPointArray = mTargetSplinePoints[mClosestTime][2]
mClosestTime = 1
for i = 1 to mPointArray.count do
(
mDist = distance mCamera.target.position mPointArray[i][1]
if mDist < mClosestDistance do
(
mClosestDistance = mDist
mClosestTime = i
mPosition = mPointArray[i][1]
)
)

mTimes[2] = mClosestTime
mPointArray = mPointArray[mClosestTime][2]
mClosestTime = 1
for i = 1 to mPointArray.count do
(
mDist = distance mCamera.target.position mPointArray[i] --[1]
if mDist < mClosestDistance do
(
mClosestDistance = mDist
mClosestTime = i
mPosition = mPointArray[i] --[1]
)
)

mTimes[3] = mClosestTime
--mCamera.position.controller.AddConstant \"mTimes\" mTimes

return mPosition"

-- this is a script stored in a string, END

floopyb
01-13-2009, 04:05 AM
cant you use the "self" command? or am I thinking of a different use?

Gibbz
01-13-2009, 04:27 AM
i tried using self, i think thats for scripted plugins. Self doesnt work either :S

davestewart
01-13-2009, 10:00 AM
It's been a while since I've been maxscripting, but does this help?

http://www.paulneale.com/tutorials/Scripting/weakReferences/weakReferences.htm

Paul will probably give you some proper advice...

Gibbz
01-13-2009, 10:16 AM
(nodeTransformMonitor node:obj forwardTransformChangeMsgs:false)

this looks promising. Ill have a look at this tomorrow @ work

CGTalk Moderation
01-13-2009, 10:16 AM
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.