Zylann / godot_heightmap_plugin

HeightMap terrain for Godot implemented in GDScript
Other
1.71k stars 159 forks source link

Collision detection broken after Linux/MacOS dedicated server export #410

Open BatteryAcid opened 9 months ago

BatteryAcid commented 9 months ago

Describe the bug I created a very simple map with some height adjustments. The player successfully walks on the ground when working in the editor, but when I export for Linux or Mac, the player (CharacterBody3D) falls through.

This is a multiplayer setup. My level is spawned into the Tree and then the player(s) are spawned into the level. They both have Collision layers set to 1.

However, I also created a test Sphere RigidBody3D but this is NOT spawned, it is statically placed in the world, but when it falls down when the level loads, it IS stopped by the terrain. So not sure why the ball is stopped but the player isn't when they "drop in" to the level.

I even once added another plane under the Terrain to see if that would collide and support the player, and it does, see last screenshot.

If anyone has any ideas or something they'd like me to experiment or test with, please let me know.

Thanks!


Environment

Player:

Screenshot 2023-11-18 at 6 10 52 PM

Test Ball:

Screenshot 2023-11-18 at 6 11 08 PM

Terrain Settings:

Screenshot 2023-11-18 at 6 11 16 PM

Terrain: Screenshot 2023-11-18 at 6 11 34 PM.

Test Plane collider under Terrain:

Screenshot 2023-11-17 at 1 50 15 PM
Zylann commented 9 months ago

not sure why the ball is stopped but the player isn't when they "drop in" to the level..

If this happens in addition to it working fine in non-exported game, then I'm not sure what the terrain/plugin would have to do with it 🤔 I have no idea, sorry. There is no special logic in the plugin that would make it behave differently in server exports, but even if it did, the ball working and the character not working still makes no sense.

Is your issue happening server-side? Or is your physics client side? Did you export your server headless (no window/graphics)? Do you have any way of testing if this works if your simulation is exported NOT as a server? If you export as DEBUG server and file logging, do you get errors? Did you exclude some resources from your server export preset? How fast is your character falling onto the terrain? Does it fall from above AFTER the terrain is added to the scene? Does it actually spawn above it server side? Which collision shape is it using? Are you able to reproduce the issue with a HeightMapShape3D setup instead of the terrain? (the plugin uses it under the hood) Does this happen with another physics engine such as Jolt?

BatteryAcid commented 9 months ago

Thanks for the quick follow up!

This is a server authoritative setup, so the items that fall through are spawned on the server and synched to the clients. So the physics is calculated on the server.

The test I did with the ball wasn't a good test, because the ball was a statically placed object, not spawned. So I changed the test to spawn the ball during game play and it too, fell through the ground.

Just like you said above: there's no special logic that would make this behave differently, my gut says it's likely not a problem with the terrain, but it's the common denominator here so I wasn't sure where else to go. I'll try some more experiments and get back to you with what I find.

Thank you for your time!

Zylann commented 9 months ago

My suspicion is that Godot behaves in a certain way in headless that makes the plugin fail to setup something, but you saw no error (even with file logging AND debug enabled?) so it's hard to even understand what's going on...

BatteryAcid commented 9 months ago

Ok, I guess I can play around with it more.

Yea, I'm not seeing any errors in the output file for the server build or in the client's debug tabs. I did enable verbose logging, this is the server:

Screenshot 2023-11-19 at 11 34 19 AM

And client:

Screenshot 2023-11-19 at 11 41 20 AM

Maybe there's a race condition? Here's a link to a short clip. It appears that the camera's SpringArm does collide with the ground, you can see it move in real quick right before falling through: https://x.com/BatteryAcidDev/status/1726281221209203010?s=20

Zylann commented 9 months ago

terrain data not set Do you see this in the exports that work, with verbose output?

BatteryAcid commented 9 months ago

I do not see that anywhere Wait, I'm going to have to retest that, I have to run out but I'll do it later today, thanks!

Zylann commented 9 months ago

image That is printing on your server. It means for some reason the terrain's data failed to load, or did not load at all for whatever reason. If you export your server with graphics, does it still print?

When verbose mode is enabled, there should be a Loading terrain data... in the log at some point. If that doesnt print, it means Godot litterally skipped over the loading of that resource (why, I have no idea, I'm not in control of that unfortunately).

For the dedicated build, I thought maybe I'm stripping visuals so I kept them in the Terrain data folder, but I don't think that applies here.

This is the only idea I have as to why it would not load it at all. If it still doesn't load it even after keeping the assets (in particular data.hterrain) then it's likely a weird Godot bug of some sort...

Zylann commented 9 months ago

I tried doing a server export of a test scene, and I checked EVERYTHING as keep in resources. Nothing makes sense: This time the terrain does receive a non-null HTerrainData, but somehow Godot is still not even running the logic that loads it (so where did it got that resource from, I wonder). So it obviously fails too because it's empty... NONE of the functions of hterrain_resource_loader.gd are called, they are supposed to be called by Godot... so I'm leaning more and more towards Godot having a bug in server exports, which means you can't use server exports... I'm baffled that there would even be a relation between server exports and custom ResourceLoader...

Zylann commented 9 months ago

I posted an issue on Godot's repo https://github.com/godotengine/godot/issues/85101 Because at this point either I'm missing something but I don't know what, or Godot has a bug.

BatteryAcid commented 9 months ago

I ran the export with a full project build and the server does print Loading terrain data... and doesn't print terrain data not set, which is I guess what you were expecting.

Thank you for looking into this and reporting the bug to Godot, because I wasn't sure where else to go with it!!!

I guess we'll see...