Static bodies added as children causing lag on collision
Asked Answered
C

13

0

Hello, I am having issues with static bodies that are added to the root of the scene through code causing lag when a character body collides with them.

The player can place down these turrets which for now are static bodies. (Though they will be changed later I'm just getting a placement system working.)


This is the code I use to get and place the turret.

Any ideas for what may cause the lag?

Corydon answered 12/10, 2023 at 3:9 Comment(0)
U
0

Corydon Is this Godot 3 or 4?

First thought that came to mind is that you are doing this while the physics engine is running. Maybe try adding the objects in a function that you call with call_deferred() so that they won't interfere with the physics code.

Unspoken answered 12/10, 2023 at 5:39 Comment(0)
T
0

If I understand you correctly, the lag is caused when the player runs into them, not when you place them. Is that correct? I can't tell what would be causing that lag, but you can try using the profiler to figure out what is causing it.

Toddtoddie answered 12/10, 2023 at 6:48 Comment(0)
C
0

Toddtoddie Yes, it is caused when the player runs into them.

Corydon answered 12/10, 2023 at 18:23 Comment(0)
C
0

Unspoken It is Godot 4. Sorry, I forgot to add the tag for Godot 4.

Corydon answered 12/10, 2023 at 18:26 Comment(0)
C
0

Unspoken I created a function uses the code after the place_location_raycast.is_colliding() if statement and replaced the code for that if statement to call the new function using call_deffered but there is still lag when the player collides with the placements.

Corydon answered 12/10, 2023 at 18:33 Comment(0)
I
0

Corydon then it might help to show the scene structure of both the bodies that can interact and what happens when they do (e.g. like signal code).

As mentioned, the profiler should show the exact problem area immediately.

Irritability answered 12/10, 2023 at 18:34 Comment(0)
C
0


This is my first time using the profiler but it seems that physics_process is what is taking the most time. The spikes on the graph occur when the player collides with the placements. Though I don't know exactly what to do to fix this.

Corydon answered 12/10, 2023 at 18:43 Comment(0)
U
0

Corydon How big is that project? Can you upload and share it? Or break it down to just the problematic part?

Unspoken answered 12/10, 2023 at 19:35 Comment(0)
D
0

This kind of sounds like https://github.com/godotengine/godot/issues/80268

Dysthymia answered 12/10, 2023 at 20:59 Comment(0)
I
0

Corydon _physics_process is a script function; what's going on in your _physics_process implementations for character bodies that are colliding with the sentries.

Irritability answered 13/10, 2023 at 10:4 Comment(0)
C
0

Irritability What is in the physics process function is in the screenshot.

Corydon answered 21/10, 2023 at 19:51 Comment(0)
C
0

Irritability Also it is just the character body default with camera controls and the forward direction changing based off rotation along the camera's Y axis.

Corydon answered 21/10, 2023 at 19:53 Comment(0)
I
0

Corydon no, I want to see the character body colliding with these static bodies and their code. The placement code shown doesn’t do anything, it is unlikely the problem.

The interaction of bodies is causing the lag from your own description. The profiler is showing user code causing this.

Create a new scene without any placement code and just the problematic bodies to reproduce the problem. Share that with the forum.

Irritability answered 22/10, 2023 at 19:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.