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() ?
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!
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
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