Rigidbody's trajectory line jittering and I don't know why!

Godot Version

4.3

Question

Good evening to all!

I followed this tutorial to give my bouncy balls a trajectory line in order to assist the player’s aim.

The idea is there, the line appears and it matches my ball’s trajectory. But! Almost every time that my ball bounces on a surface the whole line jitters and most of the times even makes a whole new line with a very odd trajectory for a split second.

The tutorial uses a Characterbody and I’m using a Rigidbody. I’m using it’s linear velocity to draw the line. I have a suspicion that the line that it draws for a split second has to do with the balls velocity as soon as its colliding with something but I don’t know much about physics tbh.

My Ball scene:
image

The trajectory line code:

extends Line2D

@onready var trajectory_bounce_probe: CharacterBody2D = $TrajectoryBounceProbe

func update_trajectory(direction : Vector2, speed: float, delta : float):
	var max_points = 100
	clear_points()
	var pos: Vector2 = Vector2.ZERO
	var vel = direction * speed
	
	for i in max_points:
		add_point(pos)
		vel.y += 980 * delta
		
		var collision_probe = trajectory_bounce_probe.move_and_collide(vel * delta, false, true, true)
		if collision_probe:
			if collision_probe.get_collider() is Trampoline and !get_parent().max_vel_reached:
				vel += vel * get_parent().bounce_increase_amount
			vel = vel.bounce(collision_probe.get_normal())
		
		pos += vel * delta
		trajectory_bounce_probe.position = pos

Code is being called on the Ball’s physics update function and sending in the normalized linear velocity vector as the direction argument, the length of that same vector as the speed and delta as delta.

Thank you for your time, please help a brother out!

im not exactly sure, but I have a feeling it might be to do with how youre calculating gravity. You’ve got it set to 980, whereas gravity is usually 9.8 in these sorts of things. It could be the physics engine freaking out that that the line is falling at almost 3 times the speed of sound. Idk how move_and_collide would handle that. also you make the check

if collision_probe.get_collider() is Trampoline and !get_parent().max_vel_reached:

and then add to the velocity again on top of that, and then call bounce(). if youre doing that intentionally thats actually really cool, but it might also be why the line is freaking out

Good morning kind sir!

Thank you for your reply.

Te value 980 is, apparently, the default gravity value for the 2D physics engine in Godot (that’s where I got the value):

Image

Plus, if there we’re something inaccurate with that it would probably not draw the trajectory right at all. I added a gif here to display the current behaviour, maybe that will help us get an idea on what could be going wrong:
ezgif-1-f32ab32ed3

When it bounced off my trampoline and made a weird line that circled around its surface, that’s what happens frequently even when bouncing off walls, usually just for a split second.

Edit: And yes, I’m checking that on purpose to increment to the trajectory the same amount that the trampoline increments to the ball, so that the trajectory will include this extra force.