Creating Tyre marks/skidmarks when braking

Godot Version

v4.2.2

Question

Hi! I'm trying to make skid marks when braking in my 2D game. I tried using Line2D to do it, but I wasn't happy with how it turned out due to the marks following the car awkwardly and then disappearing. I'd like to have them stay on the ground and later be removable through some sort of interaction (like the player driving over them with a cleaner machine). Is it possible to do this with Line2D, and I'm just missing something, or is there another way to achieve this?

I would have a different scene for tyre marks, with a preloaded sprite for the tyre mark. When the car is leaving tyre marks it can emit a signal with a position.

Your tyre mark scene would then add the tyre mark in the appropriate place, and add it to an array of tyre marks. Then remove them slowly one by one so the marks leave a trail. By taking the first entry in the array you can make it tween out before queue freeing it and remove it from the array. Then do the next one etc. To slow it down use a timer.

It may not be the ‘best’ way but is at least one way to do it.

I might try your suggestion if nothing better comes up, though it feels a bit complicated in my head (I might be too tired to fully grasp it right now, haha). I also read somewhere that ‘2D is just a viewport where you draw and mix colors,’ which might be a good approach. However, I’m not sure if this viewport is still usable in 4.2, as it seems to be greyed out.

Would your approach not cause optimization issues? I’m concerned it might lead to the creation of too many child nodes.

Well you don’t have to have an array of marks. Just have each mark have its own lifetime set and it can remove itself after a short period.

This is an interesting talk about using viewports for persistent graphical changes. The speaker uses it for tire tracks about 3 and a half minutes in. Not sure it’s what you need… but it offers an unusual approach.

Until you get to 10s or 100s of thousands of nodes it shouldn’t be a worry. Don’t think about optimization prematurely.