draw rotating line problem

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By roxasthewise
:warning: Old Version Published before Godot 3 was released.

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())
:bust_in_silhouette: Reply From: mollusca

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.

thank you. it works now.

roxasthewise | 2017-11-10 17:15