0 votes


I have my game structured like this:

  • level

    • item (position2D)

    • player (position2D)

I have a script in player and I want to draw a line between item and player, the line should update as the player moves (item will be static), like they were tied by a rope.

This is the script in player:

onready var item = getparent().getnode('item')

func physicsprocess(delta):

func draw():
line($player.position, item.globalposition, linecolor, line_width)

The problem is that the line gets drawn from the player (correct) but instead of going to the point where is the item (in this case in point (200, 100)) it gets drawn just 200 pixels to the right and 100 down where the player is.

What should I do???

Thank you!!!

asked Jun 23 in Engine by hermo (56 points)

1 Answer

+1 vote
Best answer

I think the problem here is that you're using the global position of the item, whereas you need the position relative to the player. Without testing it myself, I think you could replace



$player.position + item.global_position
answered Jun 23 by Ben Humphries (131 points)
selected Jun 23 by hermo

ohhh you are (almost) right!

it was:

item.globalposition - $playercenter.global_position

doing this it works perfectly!

thank you very much!!!

Glad you got it sorted out!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.