I have a blender file where a sphere is orbiting a force field. I want it to be more red when it's closer to the center, and more blue when it's further. I already have the math figured out, I just need to know how to get x/y coordinates in nodes.

Here's the file:

  • 1
    $\begingroup$ You probably want to look into drivers. I think they can be used as input to node fields... but maybe not. If so, a driver would likely be your best bet. $\endgroup$
    – Matt
    Aug 23, 2016 at 18:28
  • 1
    $\begingroup$ @Matt What do you mean by drivers? $\endgroup$
    – arduinoob
    Aug 23, 2016 at 18:45
  • $\begingroup$ blender.org/manual/es/animation/drivers.html $\endgroup$ Aug 23, 2016 at 19:21

2 Answers 2


Use the object info node connected to a separate xyz node:

enter image description here


Here's a node setup, which sets the colour based on the distance from a specified point in the XY plane. enter image description here
The inputs to the node group1 are as follows:
X Origin - The X coordinate of the point from which to calculate the distance
Y Origin - The Y coordinate of the point from which to calculate the distance
Inner perimeter - The threshold at which distance is set to 0 (i.e. closer than this will be all red).
Outer perimeter - The distance at which distance is set to 1 (i.e. farther than this will be all blue)

Here's the inside of the node group:
enter image description here
The Location output of the Object info node, gives the Object's location in World coordinates.
The Separate XYZ separates a vector or position in three values, one for each of X, Y and Z components of the vector/position.
The following math nodes up to and including the last Power node calculate the distance from the specified point according to the common distance formula.
The Subtract node following the Power node subtracts the Inner perimeter from the calculated distance.
The Subtract node below that calculates the distance between the Inner and Outer perimeters.
Finally, the Divide node divides the distance between the object and the centre point by the distance between the Inner and Outer perimeters.
The output is a value which at the Inner perimeter will be 0 (closer than that, will yield a negative value) and at the Outer perimeter will be 1 (farther away will yield a value that is greater than 1). The Fac input of the ColorRamp clamps the values that are outside 0-1, so the fact that we get values greater than 1 and less than 0 won't be a problem.

Here's an animated GIF of the result:
enter image description here

And here's the blend (it's basically the same blend you provided, with the material for the "planet" modified).

1When using node groups, you can edit the contents of a node group by selecting it and pressing Tab to get inside the group. When inside a node group, you can get back to the overview by pressing Tab again.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .