Raycast not updating

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Belal

I have a characterBody2D with a raycast2D. In the code I have a fire() function which works by detecting if the raycast is hitting anything( if ray.is_colliding) and getting the object (ray.get_collider) and deleting it. I noticed that every time I shoot the raycast only updates it’s position, after my fire() function is called. It is essentially a frame late. I verified my assumption with turning collision shapes visible in the debug menu. So I called ray.force_raycast_update() but it didn’t change anything. I called it every time I change the node’s position or angle in code, and directly before calling my fire() function. That also didn’t work, so I wrote:
await get_tree().create_timer(0.01).physics_frame
It solved the issue, and the waiting isn’t noticible, but it caused an issue in the movement and character trail, which I can’t solve.
Please tell me a solution.

Hi …
You have to provide your code in order to understand what is happening
Are you using raycast2D as a bullets ?

Zylo_X | 2023-03-26 11:22


 if ray.is_colliding():
   if ray.ge_collider().is_in_grouop("enemy's"):

func input(event : Inputevent) -> void:
 if event is InputEventScreenTouch:
   if event.index == 1:
Note that my code has no syntax errors,
but I may have mistyped some function names here.
Also bullet() and particles() are irrelevant to the problem.
[wrap=footnote]Belal | 2023-03-26 11:43[/wrap]

I am using a raycast2D to detect enemys and instancing
a bullet rigidbody2D node for visuals.

Belal | 2023-03-26 11:45