4

I'm trying to get an object to scale with its distance to another object, so I can then link the driver to the rest of the 639 objects in the collection.

driverwoes

I need it to somehow refer to itself, rather than explicitly selecting the object, so that when I link the driver, each of the linked objects will scale individually with their own proximity to the sphere. The intention is for each of the hexagonal objects to scale down when the sphere gets close.

In this thread, one answer says that if Use Self is checked, I can do the distance measurement in the expression itself if I use Single Property and use the sphere's matrix.world as the Object, but matrix.world isn't accepted when I try this.

In addition, is there a way I can get the driver to control XYZ scale so I don't need to use 3 drivers?

If I'm going about this in the wrong way I don't mind restarting the project.

Thanks in advance.

Attaching my blend file as requested. In this file, the driver is working correctly, but that's by specifying icosphere.083 as Object 2. I need it to work by somehow referring to "self" or "this object", so I can link the driver to other objects and have it work per object.

https://drive.google.com/file/d/15irt899Fqtbtfo_iWR2t4CbLpn6CDl5t/view?usp=sharing

Stage
  • 43
  • 5

2 Answers2

7

I noticed in your file that you had had a go with Geometry Nodes.. so as a side-note, this would be a possible arrangement:

enter image description here

The Length of the 'Relative' (i.e. owner's Object-Space) Location of the Object Info target is the distance from the GN-modified object-origin to the target object-origin. You can use some function of that for object-level proximity effects:

enter image description here

Robin Betts
  • 76,260
  • 8
  • 77
  • 190
  • 1
    Oh wow. I feel bad for Chris now. This actually suits me better than the script solution, because I can apply this to other things without feeling like I'm messing with powers beyond my ken. I hadn't fully tried to make it work with GNs, because I thought I'd need an individual GN for each hex. Now I love GNs even more than I already did. Thanks! I still need to learn scripting :P – Stage Dec 06 '21 at 14:41
4

you can use this script:

import bpy

two sample functions

def calcDistance(object):

location2 = bpy.context.scene.objects["AssaultSphere"].location
print("loc2", location2)
location1 = object.location
print("loc1", location1)
distance = (location2 - location1).length

print(distance * 3)

return distance

Add functions defined in this script into the drivers namespace.

bpy.app.driver_namespace["calcDistance"] = calcDistance

driver settings:

enter image description here

result:

enter image description here

Chris
  • 59,454
  • 6
  • 30
  • 84
  • That is excellent, and works very well. Thank you very much. I can understand most of the script, but it's beyond my ability to arbitrarily replicate. I knew this would end up with me having to learn Python, but didn't expect it so soon. – Stage Dec 06 '21 at 11:25
  • Glad I could help. – Chris Dec 06 '21 at 11:26
  • I just can say from my personal experience: you can do a lot just with Blender - but you can do a lot more with python…‼️ – Chris Dec 06 '21 at 11:28