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:
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!