I need a raycast that can be reflected when colliding with an obstacle.
I know it can also be done with line2d, but preferably I would like it to be raycast
The problem I'm having is with the RayCast and Vectors/Normals/Rotation.
thank you in advance
(sorry, i don't speak english)
extends RayCast2D
export var velocity = 1300
export var max_length = 1000
onready var laser = $Line2D
var shoot = false setget shooting
func _ready():
set_physics_process(false)
func _unhandled_input(event):
if event is InputEventMouseButton:
self.shoot = event.pressed
else:
laser.points[1] = Vector2.ZERO
func _physics_process(delta):
cast_to = (cast_to + Vector2.RIGHT * velocity * delta).clamped(max_length )
force_raycast_update()
if is_colliding():
cast_to = to_local(get_collision_point())
laser.points[1] = cast_to
func shooting(cast):
shoot = cast
if shoot :
cast_to = Vector2.ZERO
laser.points[1] = cast_to
set_physics_process(shoot )