Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

illegal self-reference help please :)

illegal self-reference help please :)

Cgillblack
Contributor Contributor
1,458 Views
2 Replies
Message 1 of 3

illegal self-reference help please :)

Cgillblack
Contributor
Contributor
ok so i want to write a little script so that if object A moves to far away from object B then object B will move closer which i thought would be simple so this is how i started.


a = $A.pos
b = $B.pos


if distance a b < 30 then
(

)
else
(

)


I havent got past this, if I put this into a position script controller then I get an error saying "illegal self-reference" which I think I understand, its trying to refer to its own position while also trying to change it hence confusion but I cant think of how else to do it.

any advice would be very helpfull.
Thank you 🙂
0 Likes
1,459 Views
2 Replies
Replies (2)
Message 2 of 3

Steve_Curley
Mentor
Mentor
Circular dependencies can be a bit tricky.

Remove the script controller (assign a PositionXYZ controller).
Assign a script controller to an unused controller - Scale is a good one to use.
Create 2 variables MyPos and OtherPos
Select MyPos > Assign Controller > select the PositionXYZ controller of the same object (the one we're wrinting the script on).
Select OtherPos > Assign Controller > the PositionXYZ controller of the other object.

The script then becomes

if distance MyPos.value OtherPos.value >= 30 then
(
)
else
(
)


Remember to move the other object, not this one, and
You MUST leave the last line as the original scale value!!!

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 3 of 3

Cgillblack
Contributor
Contributor
Thank you, got it working now 😄 but i have encountered another problem.

If i have autokey turned on then it keys every frame on the follow object can i make something "unkeyable"?

heres my code if anyones curious



a = $point001.pos
b = $point002.pos
d = distance a b
$point002.dir = a-b

if (distance a b) <= 20 then
(
$Circle001.wirecolor = green
)
else
(
$Circle001.wirecolor = red
$point002.pos = ($point002.pos + ($point002.dir*(d-20)))
)
if currenttime <= 0f then
(
$point002.pos =
)
else
(
)




thanks 😄
0 Likes