i have a script to duplicate an object, and place the duplicates at random coordinates around a spheres surface, and then point those objects away from the center of the sphere. It almost works but the calculation for the rotation of the objects is off by just enough for it to not look good at all.
I've search a lot for what i am doing wrong, but the very few solutions I've found are very out of date.
Here is my code, assumes sphere is at 0,0,0 world coordinates:
def PlaceSpike():
worldLocation = Vector((0.0,0.0,0.0))
radius = 2.4
latDeg = randint(0, 360)
lonDeg = randint(0, 360)
scale = 0.1
#Create new object to be used
pin = DuplicatePin( 'Spike', bpy.data.objects['Cone'], bpy.data.materials['pin'], 'Diffuse BSDF', Color((1.0,0.0,0.0)))
latRad, lonRad = radians( latDeg ), radians( lonDeg )
x = cos( latRad ) * cos( lonRad )
y = cos( latRad ) * sin( lonRad )
z = sin( latRad )
location = Vector((x, y, z)) * radius
locationFromWorld = location + worldLocation
scale3D = (scale, scale, scale)
aroundZ = Quaternion( (0, 0, 1), lonRad )
aroundY = Vector( (0, -1, 0) )
aroundY.rotate( aroundZ )
aroundX = Quaternion( aroundY, latRad )
rotation = Quaternion( baseRotationQuat )
rotation.rotate( aroundZ )
rotation.rotate( aroundX )
pin.scale = scale3D
pin.location = location
pin.rotation_euler = rotation.to_euler( 'XYZ' )
for x in range(10):
PlaceSpike()
I'm having a very hard time figuring out what to do, I'm not even sure anymore if i am doing it the right way and would appreciate the help, thank you.