Advertisement
Guest User

Untitled

a guest
Sep 26th, 2020
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.23 KB | None | 0 0
  1. extends RayCast2D
  2.  
  3. var is_casting := false setget set_is_casting
  4.  
  5. func _ready() -> void:
  6.     set_physics_process(false)
  7.     $Line2D.points[1] = Vector2.ZERO
  8.  
  9. func _physics_process(delta: float) -> void:
  10.     var cast_point := cast_to
  11.     force_raycast_update()
  12.    
  13.     if is_colliding():
  14.         # Show particles
  15.         cast_point = to_local(get_collision_point())
  16.         #$ColissionParticles.emitting = true
  17.        
  18.         # Get collider
  19.         var collider = get_collider()
  20.        
  21.         print('collided')
  22.        
  23.     else:
  24.         #$ColissionParticles.emitting = false
  25.         pass
  26.  
  27.     $Line2D.points[1] = cast_point
  28.    
  29. # Cast bullet
  30. func _unhandled_input(event: InputEvent) -> void:
  31.     if event is InputEventMouseButton:
  32.         self.is_casting = event.pressed
  33.  
  34. func set_is_casting(cast: bool) -> void:
  35.     is_casting = cast
  36.    
  37.     #$LaserParticles.emitting = is_casting
  38.    
  39.     # Show laser beam
  40.     if is_casting:
  41.         appear()
  42.     else:
  43.         #$LaserParticles.emitting = false
  44.         #$ColissionParticles.emitting = false
  45.         disappear()
  46.        
  47.     set_physics_process(is_casting)
  48.  
  49. func appear() -> void:
  50.     $Tween.stop_all()
  51.     $Tween.interpolate_property($Line2D, "width", 0, 10.0, 0.2)
  52.     $Tween.start()
  53.    
  54. func disappear() -> void:
  55.     $Tween.stop_all()
  56.     $Tween.interpolate_property($Line2D, "width", 10.0, 0, 0.1)
  57.     $Tween.start()
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement