Notifications
Clear all
[Closed] Script for relative effect
Sep 02, 2005 12:14 pm
How to do a script that would make $.object to affect other objects relative to the distance of the objects? for example if $.object comes within say 20 units of another it moves it -10 units on z-axis. If the distance is 10 units then the affect is -20 etc.
2 Replies
1 Reply
Sep 02, 2005 12:14 pm
Don’t know what an if loop is, but I think it’s not that simple…
Set up a scene with 20 something boxes, select first the master and then followers and then create a new script and paste the following:
-- First selected object is master
masterObj = selection[1]
followObj = selection
OffsetMax = 50
global maxDist = 0
-- First get object that's farthest away, we need this to determine the maximum offset
for obj in followObj do
(
if followObj != masterObj do
(
dist = distance masterObj obj
if dist > maxDist do maxDist = dist
)
)
-- Now offset the follow objects
for obj in followObj do
(
if followObj != masterObj do
(
offset = ((distance masterObj obj) * OffsetMax) / maxDist
-- the following line can be any property of an object you want to influence
obj.pos.z += offset
)
)
Hope it makes any sense!
Cheers,
Johan