Godot 3 to Godot 4 migration

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 ???

tween_property’s arguments are

  1. object to edit
  2. property of said object
  3. final value
  4. duration of tween

I think the duration is the only one that needs changing. If you want to also record the starting value you can use .from()

func appear() -> void:
	if is_instance_valid(tween):
		tween.kill()
	tween = create_tween()
	tween.tween_property($Line2D, "width", 10.0, 0.2).from(0.0)
1 Like

Thanks man, You have been a great help !!!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.