Godot Version
4.4
I’ve created a shotgun blast that involves a dozen short raycasts so that enemies can get hit by partial shots, corners can half-block, etc. Each of the raycasts instantiates a line2d for the visual aspect of the shot, (I thought about using collidable GPU particles for this, but just haven’t been able to get them working right) which draws from the shot’s origin point out to either the collision point of the hitscan or a node that marks its target point, if the shot misses.
The raycasts work perfectly and never miss, from what I can tell. But the line2ds tend to draw their full length a few frames ahead of the raycast marking the collision, and then reverting back to their collision point target instead.
Do raycasts take a few frames to calculate? And if so, how do I work around that? Also happy to hear better methods, this was just the best I could come up with.
Here is the code that governs the raycasts and the generates the lines:
for raycast in hurtbox_raycasts.get_children():
var endpoint: Vector2
var ray_hit_assigned = false
if (raycast.is_colliding() == true) and (ray_hit_assigned == false):
ray_hit_assigned = true
endpoint = raycast.get_collision_point()
elif (raycast.is_colliding() == false) and (ray_hit_assigned == false):
ray_hit_assigned = true
endpoint = raycast.get_child(0).global_position
else: print
var pellet = PELLET.instantiate()
get_parent().add_child(pellet)
var starting_position = position
pellet.start_point = starting_position
pellet.end_point = endpoint