How can I render a line correctly from a moving object (so that there is no offset relative to velocity)?

I am debugging a function that uses a RayCast from my vehicle position to the world plane. To help me see what is going on, I use

Debug.DrawLine(myVehicle.transform.position, rayCastHit.point) //in FixedUpdate

The problem is that when the vehicle is moving, the line is drawn as if it lags behind - that is, it is not rendering from the vehicle's position, but rather some point away from it (and in the opposite direction of the vehicle's movement). As soon as the vehicle stops, the line is rendered at the vehicle center again as it should.

It looks like the transform.position does not coincide with the position where the vehicle is rendered.

As you can imagine, this makes debugging very difficult, as I cannot trust any information obtained with a Debug.DrawLine.

Is there a way to have it always render it from the right position, so that it starts from the vehicle position?

I believe Skovacs has the explanation right. The physics engine and scripts tend to change the position of the object, often in Update(). If your code is in Update() you are simply calculating using the original position, which is in the process of getting recalculated.

Try putting your line render code in LateUpdate instead. It should read the position after it's being updated. That's where you'd typically put code to implement a camera that follows an object, for example.

See also the Unity manual's notes about update order.

I've found transform.position tends to lag a little behind the current position when moving with forces - generally I tend to find using rigidbody.position a lot better