Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends RayCast2D
- var is_casting := false setget set_is_casting
- func _ready() -> void:
- set_physics_process(false)
- $Line2D.points[1] = Vector2.ZERO
- func _physics_process(delta: float) -> void:
- var cast_point := cast_to
- force_raycast_update()
- if is_colliding():
- # Show particles
- cast_point = to_local(get_collision_point())
- #$ColissionParticles.emitting = true
- # Get collider
- var collider = get_collider()
- print('collided')
- else:
- #$ColissionParticles.emitting = false
- pass
- $Line2D.points[1] = cast_point
- # Cast bullet
- func _unhandled_input(event: InputEvent) -> void:
- if event is InputEventMouseButton:
- self.is_casting = event.pressed
- func set_is_casting(cast: bool) -> void:
- is_casting = cast
- #$LaserParticles.emitting = is_casting
- # Show laser beam
- if is_casting:
- appear()
- else:
- #$LaserParticles.emitting = false
- #$ColissionParticles.emitting = false
- disappear()
- set_physics_process(is_casting)
- func appear() -> void:
- $Tween.stop_all()
- $Tween.interpolate_property($Line2D, "width", 0, 10.0, 0.2)
- $Tween.start()
- func disappear() -> void:
- $Tween.stop_all()
- $Tween.interpolate_property($Line2D, "width", 10.0, 0, 0.1)
- $Tween.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement