Detecting if an object touches a Line2D

Godot Version

4.3

Question

I am currently making a racing track generator in godot. To put it simply, I create randomly generated racetracks. I plan to use RL Agents to make an IA drive around these tracks. The problem is that I need my race car to detect if it is on the track or not. I used _draw() for the visuals, but wasn’t able to find a collision detection method for _draw(). So, using my track info, I was able to make a Line2D that perfectly followed the shape of my racetrack. But, here again, the same problem arises: How do I detect if the car is inside my Line2D (either partly or fully).

In a few words : Detect if CollisionObject2D is inside a Line2D.

Thanks in advance.

(P.S: I am not a native English speaker, so please pardon any spelling mistakes.)

You could create collision shapes by script as described here: Line2D Collision :: Godot 3 Recipes

1 Like

Is it possible to use a single large hitbox? I use bezier curves in my track, and each track has around 1500 to 2500 points, to I am scared it would lag my game and be a pain to check for each rectangle if it touches my car.
Here is a picture of a typical track generated :

I think that would not be a problem as you would check the other way around. So check if the car enters any of the colliders.