The code is ther to rotate the area but it dos not work both print massages are true if input (“rotate”) is pressed in the area that i want to rotate.
And sorry if i forgote some infomation.
te code coms from this youtube video: https://www.youtube.com/watch?v=2YT3TtsWt9w
her is my scene tree:
This is the code:
extends StaticBody2D
#@onready var static_body_2d: StaticBody2D = $"."
#@onready var sprite_2d: Sprite2D = $Sprite2D
@onready var area_2d: Area2D = $Area2D
var is_dragging: bool = false
var mouse_click
func _input(event: InputEvent) -> void:
if event.is_action_pressed("rotate"):
is_dragging = true
print (is_dragging)
else:
is_dragging = false
mouse_click = false
if is_dragging == true and mouse_click == true:
area_2d.look_at(get_global_mouse_position())
func _on_area_2d_input_event(viewport: Node, event: InputEvent, shape_idx: int) -> void:
if event.is_action_pressed("rotate"):
mouse_click = true
print (mouse_click)
I think it has something todo with area_2d.look_at(get_global_mouse_position())
Try using the same scene structure your tutorial uses. There’s only one collider there, yet you have two of them.
It now has nearly the same structure, except for the root node.
I did this because she moved the root node, but my version of the engine said do not move the root.
Because of this, I added another node2D as the new root.
I also found out that it prints everything except for ("both = true").and it only print when i click it not when i hould clicking wich i weard bcause i used
if event.is_action_pressed("rotate"):
extends Node2D
#@onready var static_body_2d: StaticBody2D = $"."
#@onready var sprite_2d: Sprite2D = $Sprite2D
@onready var area_2d: Area2D = $Area2D
var is_dragging: bool = false
var mouse_click
func _input(event: InputEvent) -> void:
if event.is_action_pressed("rotate"):
is_dragging = true
print ("is_dragging")
print (is_dragging)
else:
is_dragging = false
mouse_click = false
if is_dragging == true and mouse_click == true:
print ("both = true")
area_2d.look_at(get_global_mouse_position())
func _on_area_2d_input_event(viewport: Node, event: InputEvent, shape_idx: int) -> void:
if event.is_action_pressed("rotate"):
mouse_click = true
print ("mouse_click")
print (mouse_click)
Your code doesn’t match the tutorial code. When following tutorials first do everything exactly as the tutorial does. Once you get it working like that, then start to improvise and adapt to your specific needs.