How to write the object position itself into position script controller

Hi ...
I'm curious about the expression script because I rarely use it, only once in a while ...

such a simple case :

dist = ( distance $.pos $sphere001.pos )
$.pos.z += dist

my question is :
how to write '$.pos' itself into expression of postion script controller ?

thanks

AttachmentSize
positionscript_controller_failed.jpg193.83 KB

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
barigazy's picture

...

Try this one

sph = $Sphere001
tea = $Teapot001
ctrl = float_script ()
tea[3][1][3].track = ctrl
ctrl.addConstant "fixPos" (tea.pos)
ctrl.AddObject "trgObj" sph
ctrl.AddNode "srcObj" tea
ctrl.script = "(distance trgObj.pos fixPos)"

bga

Budi G's picture

hi barigazy, thank you .. its

hi barigazy, thank you .. its working correctly :)

but I'm still confused about expression script.
I saw some scripts from the other scriptor its same/closest case.
if some user deleting the target object is will getting error (some problem)

mm .. so I'm looking for to fixing that's error

a snippet method, such as:
if isValidNode trgObj then (distance trgObj.pos fixPos) else fixPos.z

it's working but it's making move the object(tea) to zero z position,
as I want the object(tea) position do not impact anything when the target has been deleted.
z position should stay on current z position.

any suggestion ?

barigazy's picture

...

Create one more Constant "fixTrgPos" which will represent starting target position
like I did for source object

if isValidNode trgObj then (distance trgObj.pos fixPos) else (distance fixTrgPos fixPos)

bga

Budi G's picture

nicely :)I did what you

nicely :)
I did what you said...

sph = $Sphere001
tea = $Teapot001
ctrl = float_script ()
tea[3][1][3].track = ctrl
ctrl.addConstant "fixPos" (tea.pos)
ctrl.addConstant "fixTrgPos" (sph.pos)
ctrl.AddObject "trgObj" sph
ctrl.AddNode "srcObj" tea
ctrl.script = "if isValidNode trgObj then (distance trgObj.pos fixPos) else (distance fixTrgPos fixPos)"

but it's almost close to the goal.

with your method it works if the target(sphere) has not moved.
but when the target has been moved and the user deletes the target then the source(teapot) position still moving to another place.

I need the source position must be in the same place when the target erased, at any time in which the target has moved or not.

thank you again barigazy

regards

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.