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

Kinematic Rigid Bodies do not update their position with the world despite calling update_kinematic_position #141

Open
samaursa opened this issue Dec 27, 2024 · 4 comments
Assignees

Comments

@samaursa
Copy link

samaursa commented Dec 27, 2024

I have tested the following successfully:

  • 2 rigidbodies moving towards each other and generating accurate contacts
  • 1 rigidbody moving towards a non-moving (but not static) kinematic body and generating accurate contacts

If I move the kinematic RigidBody using update_kinematic_position, the contact points generated are as if the kinematic RigidBody never moved i.e. their position is that of when the kinematic RigidBody was first created. In effect, it seems that kinematic RigidBodies cannot be moved at all.

Perhaps there is another call that needs to be made per entity that is a kinematic RB to update the position with the world that I don't know of?

@xissburg
Copy link
Owner

Thanks for bringing this up! These functions have been neglected for quite a while and need to be revisited or perhaps even removed to avoid confusion. The reason they're not working properly though is because they're not calling registry.patch after modifying components. For the time being, the correct way to move a kinematic is by assigning position and orientation and also the velocity. See ExamplePlatforms::updatePhysics.

@xissburg xissburg self-assigned this Dec 28, 2024
@samaursa
Copy link
Author

samaursa commented Dec 31, 2024

Thanks @xissburg I'll try that out

or perhaps even removed to avoid confusion

If they are removed, how do we move the Kinematic bodies without these functions?

Edit: oh I see... do you mean we should patch the position/orientation and velocity directly?

@xissburg
Copy link
Owner

Edit: oh I see... do you mean we should patch the position/orientation and velocity directly?

Exactly. It's important to set the appropriate angular and linear velocity for constraints to behave correctly.

@samaursa
Copy link
Author

samaursa commented Dec 31, 2024

@xissburg since I am using the update_kinematic_position function, I updated it to test whether the overlaps will work or not:

void update_kinematic_position(entt::registry &registry, entt::entity entity, const vector3 &pos, scalar dt) {
    EDYN_ASSERT(registry.any_of<kinematic_tag>(entity));
    auto &curpos = registry.get<position>(entity);
    auto &vel = registry.get<linvel>(entity);
    vel = (pos - curpos) / dt;
    registry.patch<position>(entity) = pos;
    registry.patch<linvel>(entity) = vel;
    registry.patch<angvel>(entity) = registry.get<angvel>(entity); // I don't think this is required, but doing it just in case
    registry.patch<orientation>(entity) = registry.get<orientation>(entity); // I don't think this is required, but doing it just in case
    curpos = pos;
}

However, these changes do not seem to be working as expected.

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

No branches or pull requests

2 participants