Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HeightMapShape collision does not update properly when the body is translated #37337

Open
Tracked by #45333
Zylann opened this issue Mar 26, 2020 · 2 comments
Open
Tracked by #45333

Comments

@Zylann
Copy link
Contributor

Zylann commented Mar 26, 2020

Godot 3.2.1
Godot 3.1
Windows 10 64 bits

Following this issue (have a read for insights): Zylann/godot_heightmap_plugin#129

Adding a HeightMapShape to a static body in the editor (through the use of tool scripts) works fine, until the body is moved to a non-origin position.
All raycasts that are not going through the AABB it occupied at origin will always miss.
This causes other plugins relying on raycasts to fail, and the Snap-to-Floor functionality also fails.

This does not reproduce in a running game, and it only happens with this type of shape.
It happens regardless of the body being moved or being loaded not at origin.

Reproduction steps

Investigating what is actually happenning wasn't obvious at first, so I created a new plugin which allows to "see" the result of raycasts going from the camera to every visible pixel, allowing to visualise collisions directly:
https://github.com/Zylann/godot_collision_scanner
(see the issue linked above for more screenshots).

Here is a simplified project:
HeightmapTranslated.zip

  1. Open main.tscn: it contains a tool script which setups a heightmap with collider.
    image

  2. Go to ProjectSettings, and enable the Collision scanner plugin. The view will darken, and after a few seconds you should see raycast results, matching the terrain.
    image

  3. Now click on the Terrain node, and translate it by about 50 units along X or Z.

  4. Move the view a bit to force an update of the collision viewer: the view will turn dark again, and after a few seconds you'll see updated raycast results: only those that went through "the AABB the terrain would cover if it was at origin" will show up, everything else will remain dark. This is wrong, it should still match the visuals.
    image

Note: the body did call PhysicsServer::body_set_state(), and you can see collision actually matches the translated body, just not outside of this AABB. Something else must be missing.

@nullinsight
Copy link

Using Godot Engine v3.2.2.stable.official

I am a newb so I am not 100% sure if this is related but I am running into a similar issue using intersect_ray in the editor with a tool script.
If I put an object in the world with a collider and run the tool script for checking overlaps with intersect_ray it works, but if I move the object and try again it doesnt work until I re-check the collision layers on the object.

godot_bug

The function to check intersects is this (nothing special)

func check_collision(ray_start, ray_end, coll_m):
    var space_state = get_world().direct_space_state
    var hit = space_state.intersect_ray(ray_start, ray_end, [], coll_m)
    if not hit.empty():
        print(hit)
    return hit

@Arnklit
Copy link
Contributor

Arnklit commented Nov 21, 2020

Appears to be a general issue with colliders, logged here #43744

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants