[Closed] Scripted Controller Help, Acess own nodes pos?
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 [b]mCamera.target.position[/b] mTargetSplinePoints[1][1]
"
$.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…
$Camera01.target.position works for me.
Silly question, is it actually a Targetted Camera or a Free Camera?
What error message are you getting?
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
Post your controller script.
The info you want should be in there.
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 ?
-- 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
i tried using self, i think thats for scripted plugins. Self doesnt work either :S