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

Wrong HField vertical scaling in unity plugin #1930

Open
kezzyhko opened this issue Aug 27, 2024 · 2 comments
Open

Wrong HField vertical scaling in unity plugin #1930

kezzyhko opened this issue Aug 27, 2024 · 2 comments
Labels
bug Something isn't working Unity Unity plug-in

Comments

@kezzyhko
Copy link

Description

Video with the problem is attached below

When using a terrain (hfield geom) in Unity, physics collisions may not match the rendered visuals. This happens in case when terrain data contains heights in smaller range than [0..1]. For example, if terrain is a flat plane at height 0.7, mujoco will think that highest point is at height 1, and collision will happen at height 0.7 * 0.7 = 0.49. But as soon as we add one point at height 1, everything starts working correctly.

Steps to reproduce

  1. Create empty project in Unity and add MuJoCo package
  2. Import the attached .unitypackage file (HFieldBug.zip)
  3. Open the scene and hit play (notice how the cube falls through the terrain, but then stops)
  4. Stop simulation and tick the "Add Workaround Point" on "TerrainCreator" object
  5. Hit play (notice that the cube no longer falls through)

Video

HFieldBug.-.HFieldBugScene.-.Windows.Mac.Linux.-.Unity.2022.3.28f1._DX11_.2024-08-27.20-52-47.mp4

Versions

It probably does not depend on particular versions, but I'm gonna include them anyway

OS: Windows 10
MuJoCo: 3.2.0
Unity Editor: 2022.3.28f1

@kezzyhko kezzyhko added the bug Something isn't working label Aug 27, 2024
@Balint-H
Copy link
Collaborator

Balint-H commented Aug 28, 2024

Hello!

Thanks for the top quality bug report! I implemented this feature originally with normalized heightmaps in mind (always ranging from 0 to 1) which is why I first missed this issue. I am aware of this bug, and I think this commit fixes it (and adds inspector tools to add terrain automatically): https://github.com/Balint-H/mujoco/tree/feature/unity-hfield-context

There's an open PR for it that has not yet been merged.

However I've mainly tested it in my own use cases and I'd really appreciate if you could give it a go as well (the commit is for MuJoCo 3.1.4). If it still doesn't work for you I'll go through the scenes you shared and send in a fix ASAP.

If it does work I'll ask for someone at DM to merge in the PR.

I'm glad others are using the plugin as well, so let me know if you have other questions.

@kezzyhko
Copy link
Author

@Balint-H
Yep, I have seen your PR, but for some reason I didn't think it would fix that bug. Anyway, I have tested my usecase with MuJoCo 3.1.4 + plugin at https://github.com/Balint-H/mujoco.git?path=unity#feature/unity-hfield-context, and it works perfectly. Now waiting for the PR merge :) Thanks for your help and for your contributions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Unity Unity plug-in
Projects
None yet
Development

No branches or pull requests

3 participants