Odd drawLine() behavior with Parented objects

I’m trying to draw a line with bge.render.drawLine()
between two objects. This all works well if the two objects are not parented to anything.
If any of the objects are parented (even though I’m using obj.worldPosition for line positions),
there is an odd delay and even error on positioning.
I have attached an example file here.
Red is parented to an empty and blue targets represents the non-parented objects.

Between these two blue objects drawing line works beautifully, but on the red target drawLine goes nuts.

Any ideas what could cause this and how could I calculate parented object worldPosition without such odd behavior for drawLine() ?

drawLine_issue.blend (507 KB)

use a separate item to draw the line?

T = scene.objects[‘Object1’]
T2 = scene.objects[‘Object2’]
TP=T.worldPosition
T2P=T2.worldPosition
render.drawLine(TP,T2P,(255,255,0))

Changing code like that has no impact what so ever.

You know that the code is based on data that is already on screen? This means the line is always one frame behind. Luckily in your situation it is hard to recognize that.

Your real problem is a different one. You draw a line from blue to the empty. But the red cube does no match the position of the empty as it gets moved away by its logic.

Hmm Interesting. You found a flaw from my problem llustration file haha, which leads me to think that there is something wrong with my actual project too. Thank you for pointing this out!

Solution use last frames random, to do this frames move?

so the drawline will be targeting the future location of cube?

Frame0 (no move)
Roll random
Store next frames move
Draw line to future move

Frame1 (frame 0 move)
Roll random
Store next frames move
Drawline to future point

and so on?

afaik there 2 solutions(or 3)
1-> rotate the objects using the matrices (this due a change immediate, differently to applyRotation, so no lag… the drawline function must be after the rotation in the code)
2-> put the function drawLine as callback inside scene.pre_draw (ie: scene.pre_draw.append(draw))
3-> keep the lag :slight_smile:

the second case is decisely the more complex .
you should put a class manager inside predraw rather than the the function directly , the class then can eliminate the broken functions