+2 votes

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?

asked Mar 8, 2016 in Engine by sheosi (14 points)

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...

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).

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

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.

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...

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.

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

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).

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.