ScriptSpot

Forum topic · General Scripting

How to write the object position itself into position script controller

By Budi G · 2013-09-03

Downloads
Description

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

Comments (4)

barigazy · 2013-09-03

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)"

Budi G · 2013-09-04

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 · 2013-09-04

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)

nicely :)I did what you

Budi G · 2013-09-04

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