# Calculating position difference in a driver

Suppose I have an object, that I move from A to B (by pressing the G button) on the XY plane. I want to automatically orient it, so it always faces the direction of the movement. Furthermore, I want it to rotate as if it is a wheel.

Given a linear motion, I want to set the orientation with drivers, so the Y points forward and Z points upward.

As there are no keyframes available, the function that updates the direction and the rotation of the "wheel" must be invoked regularly to capture the current and the previous positions and make the needed updates.

Initial scene:

The wheel has been dragged/is being dragged:

Can it be achieved ONLY with drivers?

• Deducting the orientation just from the starting orientation and the positional offset is not possible. You would have to have a function describing the motion or approximate it in small steps. Or do you only want this for a single axis (X), like your equation suggests. Commented Dec 21, 2019 at 10:59
• @Leander yes, only around one axis (sphere's local X axis). For that the sphere must also automatically align its Y axis with the direction of the movement. The problem is calculating the positional offset in a driver.
– user57276
Commented Dec 21, 2019 at 11:14
• I have edited your question, because in this case "drag around the XY-Plane" would be incorrect. Please correct it if i misunderstood Commented Dec 21, 2019 at 11:18
• @Leander you have probably misunderstood it. The sphere is moved in a plane and reorients itself to face the direction of the movement, so that it can be rotated around its X axis like it is rolling.
– user57276
Commented Dec 21, 2019 at 11:25
• This is a hack to store the previous position. (Edit) Whops, the dependency graph rework from 2.8 broke it. Commented Dec 21, 2019 at 13:50