Godot Version
4
Code
extends RayCast2D
@onready var tween: Tween
var is_casting := false:
set = set_is_casting
func _ready():
set_physics_process(false)
$Line2D.points[1] = Vector2.ZERO
func _unhandled_input(event : InputEvent) -> void:
if event is InputEventMouseButton:
self.is_casting = event.pressed
func _physics_process(_delta: float) -> void:
var cast_point := target_position
force_raycast_update()
if is_colliding():
cast_point = to_local(get_collision_point())
$Line2D.points[1] = cast_point
func set_is_casting(cast: bool) -> void:
is_casting = cast
set_physics_process(is_casting)
if is_casting:
appear()
else:
dissapper()
func appear() -> void:
if is_instance_valid(tween):
tween.kill()
tween = create_tween()
tween.tween_property($Line2D, "width", 0, 10.0)
func dissapper() -> void:
if is_instance_valid(tween):
tween.kill()
tween = create_tween()
tween.tween_property($Line2D, "width", 10.0, 0)
Question
HI, I was following this tutorial, and tried to convert that godot 4 code to godot 3. but here the beam appears but not disappearing. What to do now ???