0 votes

Hi, i have certain problem about drawing a line from Vector2(0,0) to direction of my object.
It seems that if i rotate my object 90 degrees, the line rotates 180 degrees, it's like the line always rotate twice degrees of my object.

I hope that you guys can help me.

here's my code

func _fixed_process(delta):
    update()
    process_input()
    process_movement(delta)

func _draw():
    draw_line(direction * 100, Vector2(0,0), Color(1,1,1))

func process_input():
    if(Input.is_key_pressed(KEY_A)):
        orientation += rotationSpeed
        if(orientation > maxAngle):
            orientation -= 360
    if(Input.is_key_pressed(KEY_D)):
        orientation -= rotationSpeed
        if(orientation < 0):
            orientation = 0 - (orientation - 360)
    set_rotd(orientation)

func process_movement(delta):   
    direction.x = sin(get_rot())
    direction.y = cos(get_rot())
in Engine by (26 points)

1 Answer

+2 votes
Best answer

The drawing commands already get the node transform applied to them so there's no need in your case to rotate the line separately:

draw_line(Vector2(0, 100), Vector2(0,0), Color(1,1,1))

should work.

by (1,540 points)
selected by

thank you. it works now.

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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.