Some random offset coming in trail , not starting from the player body

Godot Version

4.3

Question

i made a player that moves randomly and aligns it’s face according to it’s direction , now i added a trail as a child node of this player , but the trails are always drawn from some offset, they are not connected to the player but move here and there
this image contains the code for trail

youtube video of issue - https://www.youtube.com/watch?v=uBN2BZrds4w
github repo - GitHub - Vivek13130/Boids


PLEASE HELP ! IT’S VERY URGENT


Line2D uses local coordinates, so you have to convert them to local coordinates with to_local(global_position)

1 Like

brother , i tried this and it is giving (0,0) as output everytime ,
you can see the hierarchy and scene structure and script structure easily , please help , it’s still not working , i am tired of looking for solutions online

This quite tricky because the line moves with the player. Use your old solution and set top_level to true on the trail-node

1 Like

can’t find anything like set top level anywhere ?!

In the Inspector under “CanvasItem”

1 Like

brother, thanks a lootttttttt , you don’t know how frustrated i was , watched like 20 vids , chat gpt and all , but can’t find a solution

thanks a lot brother , can’t thank you enough for this , finally they are working :slight_smile: :sob: :sob:

can you plz explain what exactly was going wrong ? and how setting top level corrected it

1 Like

The problem is that the line2d needs local coordinates, but the points you want to give it, are from the parents-position, which are (0,0) in local-coordinates of the lines view, because the line always moves with the parent.

Activating “Top Level” stops the line from moving with the parent and therefore is able to use the parents-global_position as local coordinates, resulting in the actual points you want to have

Im glad i was able to help :smiley:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.