Dynamic Multi-point Physical Line?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By sheosi
:warning: Old Version Published before Godot 3 was released.

I’ve been wanting to make a line which is made at runtime (using points) and I would like to detect collisions against it (also, I would like it to stop from some entities from crossing it). Also I need to change this line at least once every few frames (this is because is made by the player)

I’ve tried staticbody and they take way too much time to “construct” (adding one drops my FPS), and other kind of bodies does not seem to work at all, so how can I do this?

I think CollisionPolygon2D is what you want, but there seems to be a bug were the editor crashes if you try to increase it’s size. Going to report it on Github right now…

batmanasb | 2016-03-08 21:50

I don’t think this is valid because: a) it’s only useful for polygons ( not lines alone). b) Can only be used in the editor and it does not exist at runtime (and what I want to do is at runtime).

sheosi | 2016-03-08 22:44

Maybe try adding shapes to the StaticBody2D at runtime, something like SegmentShape2D looks ideal

batmanasb | 2016-03-08 22:52

Yeah I thought that too and that was what I tried, and every time I added a SegmentShape2D the FPS drop, and that’s a problem I need to do this at least once every few frames.

sheosi | 2016-03-09 07:20

So you are constantly drawing new shapes every few frames? So in less than a minute you reach over 1000 shapes? That’s probably the issue right there. To increase performance try tweaking “cell_size” by powers of 2. Also, you should try and set a fixed number of shapes. Something along the lines of having a list of 200 and changing the position of the first one in the list instead of spawning number 201. Or maybe just erasing the first one to keep it at 200. Too much physics is a major performance hit.

Edit: I might actually be wrong here. StaticBody2D is supposed to not be CPU intensive at all, so maybe that’s not the issue or you may have to many shapes even for that…

batmanasb | 2016-03-09 07:28

It’s not that, i don’t have any problems with the performance by itself when using StaticBody2D, the problem comes when I try to add a new shape, this happens even at the start and it gets worse latter.

sheosi | 2016-03-10 15:02

What if you instance a scene that includes a staticbody with a lineshape?

Bojidar Marinov | 2016-03-15 09:05

No luck, neither, actually seems to cause even more than just making the lineshape and adding it, I’m starting to think the problem is in the code around it, I’ll test it later.
EDIT: No, it doesn’t seems to be program, the code only happens once (and not multiple times as I thought it might happen, out of ideas now).

sheosi | 2016-03-29 00:18