Zylann / godot_heightmap_plugin

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

The collision seems to be lost in the Editor but not when playing the Scene #129

Open RonanZe opened 4 years ago

RonanZe commented 4 years ago

I'm trying to use the Scatter plugin an the snapping with "Page Down" shortcut and It do not always works. It's a bit fishy because sometimes it comes back when I'm loading an other scene with a Terrain and then I work everywhere again.

I have a more precise case to describe: My project have 2 scenes. Each scene have 1 Terrain Node in 4k. When I "Save All Scenes", the Scatter Tool still works on the current scene. But when I switch to the second scene, It do not works anymore. Then I go back to the first scene and It is not working either.

And when I switch again on the second scene, everything seems to go back to normal.

Hope that's clear, Ron

Zylann commented 4 years ago

I added some debug code in the plugin which throws a bunch of raycasts down to see where they land on the terrain (if they ever land). The collider is correct. I could not reproduce the problem by just switching scenes, unless you meant closing and reopening them?

I tried the "Page Down" tool, it just doesn't work. Even though my collision tests did. In fact, it snaps to somewhere way higher than the terrain, while the boxes I snapped using intersect_ray all landed on the surface. image Worse, it is detecting the box itself as collision... if I turn off its collision, it displays the message can not find solid floor. Which leads me to believe this snap tool relies on the presence of built-in nodes to work, doesn't consider plugin nodes like terrain, and does not even use the available collision information... I'm really confused, but I believe the snap tool needs improvements. It uses intersect_ray, but somehow it still misses the presence of my collider. See https://github.com/godotengine/godot/pull/20022#issuecomment-407397650

I tried with the scatter plugin, could not reproduce the problem. I opened two scenes with a terrain in them, put a scatter node in one, switched to the other, clicked "Save All Scenes". The collider of the second scene was still correct. I switched to the first scene, the collider also remained correct and the scatter plugin continued to work.

Note: currently the collider does not update automatically when the terrain is modeled, which is done by going to Terrain -> Update editor collider. But that's a different issue.

RonanZe commented 4 years ago

Thanx for your investigations. The snap tool need in fact a lot of improvements. In it's current state, it feel more like a work in progress stuff that a well design build-in tool.

I'll tried to send you a simplified demo file later today. Is it possible in GitHub or do I have to make a link?

Zylann commented 4 years ago

If your project is small enough you can zip it and drag and drop in a github post.

RonanZe commented 4 years ago

With the heightmap and all the png, it's 100Mo. I put a temporary link that will last 30 days or more: https://www.dropbox.com/s/hntlx1hdvqmiuiy/Terrain-Scatter-Bug.zip?dl=0

When cleaning the project, the bug seems to have evolved a little bit: Just open the project, click on the scatter node and try to paint (and move the camera above the terrain if you don't see it). It works when you Scatter/paint on the the Arrow Widget (?!) of the "Select Mode" but not everywhere else on the viewport. Arrow

Note: it always print "Paint scenes" in the Output window even when it do not put a new scatter object.

I have removed the 2de scene with the 2de Terrain from the projet. When clicking between the 2 scenes, the problem did disappeared until closing and reopen the project

Zylann commented 4 years ago

From what I can see so far, the collider appears to only exist within the +X+Z quadrant of the map. No hits get registered elsewhere. The hits within the collidable area are correct so it's not really offset. I'll keep investigating the cause.

Zylann commented 4 years ago

So this is what the raycasts "see": image Now I haven't the faintest idea why a whole part isn't detected, but I can say this is view-dependent. image image It really feels like there is a "Bounding Box" surrounding that quadrant of the map, and raycasts going through it can reach any point of the terrain. But if they don't go through that box, they will always miss, even if the terrain is actually present in front of them. This happens despite the collider being translated here: https://github.com/Zylann/godot_heightmap_plugin/blob/7ea293da732eecc089af0cb18a024c6d4b135421/addons/zylann.hterrain/hterrain_collider.gd#L107

I thought it would be a bug I introduced in Bullet when implementing raycast acceleration, but it also reproduces in Godot 3.1, so it's not that: image (partial preview cuz raycasts are deadly slow in this version).

Only workaround for now is to not translate the terrain...

Zylann commented 4 years ago

I can also confirm this does not reproduce in-game. This is really specific to the editor...

Zylann commented 4 years ago

The following workaround seems to work: Go to the Terrain menu, click "Update editor collider". This forces to recreate the collider. image