Hey guys,
I'm using a raycast with a line2d to show my ball's predicted trajectory.
Sometimes it works flawlessly:
https://imgur.com/2wGUvTT
Other times, the reflected line does not show, but raycast does:
https://imgur.com/94Jpuyt
I've printed out the coordinates for when the collision happens, and it all checks out. The line just does not get drawn at random angles.
Here is my section of code for bouncing raycast and drawing the line:
# Ray 1 collision (first bounce)
if lineCast.is_colliding():
line.add_point(pos)
var lineCastColPoint = lineCast.get_collision_point()
var lineCastColNormal = lineCast.get_collision_normal()
var incoming_direction = lineCastColPoint - lineCast.position
var outgoing_direction = incoming_direction.bounce(lineCastColNormal)
line.add_point(lineCastColPoint)
# Ray 2 collision (second bounce)
lineCast2.position = lineCastColPoint
lineCast2.cast_to = outgoing_direction
if lineCast2.is_colliding():
var lineCast2ColPoint = lineCast2.get_collision_point()
line.add_point(lineCast2ColPoint)
else:
line.add_point(lineCastColPoint + outgoing_direction)
Any suggestions? Thanks in advance!!