How we can draw prediction line in Godot 4.2.1?

Godot 4.2.1

I am new in Godot and I have small project, and I want to create small bubble shooter game and I did not know how can I draw prediction line like in image below in Godot 4.2.1, my scene tree is like that, RigidBody2D(Root) and Sprite2D, CollisionShape2D is child it, and my script code like that for shoot the ball: `

extends RigidBody2D

var launcher_position
var shooting = false

func _process(delta):
	if (Input.is_action_just_pressed("click")):
		launcher_position = get_global_mouse_position()
		shooting = true

	if shooting:
		var current_position = get_global_mouse_position()
		var dir = (current_position - launcher_position).normalized()
		linear_velocity = dir * delta * 20000

	if (Input.is_action_just_released("click")):
		shooting = false

and image :

and I want to adding prediction line like image, any idea will appreciated.

1 Like

You cast a ray, and you need a collidable body that is just off the screen when the ray hits you cast another ray at the point of collision finding the angle of reflection. You also keep in mind the total length of the line for the second ray.

Godot should have a 2d line class that can make your segmented line. And the shape at the end you can just place at the end of the ray cast position.

1 Like

is there any sample for this one, I didnt find anywhere about it, by the tnx for your answer, appreciated.

There is a tutorial in the Godot docs