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

Changing rigid body type on react update doesn't seem to work #314

Open
jcowles opened this issue Feb 19, 2023 · 6 comments
Open

Changing rigid body type on react update doesn't seem to work #314

jcowles opened this issue Feb 19, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@jcowles
Copy link

jcowles commented Feb 19, 2023

I have a rigid body:

<RigidBody
    position={props.position}
    scale={[1, 1, 1]}
    type={props.physicsType}
    ref={el => { rigidBodies[props.index] = el; ref.current = el; }}>
...

If I change props.physicsType to "dynamic" (from "kinematicPosition"), the RB does not become dynamic, however if I initialize props.physicsType with the value "dynamic" it works.

I've also tried calling addForce with wake=true, just in case the objects were sleeping and pushing the objects with another object, but nothing works.

The React component is definitely re-rendering when the value changes and has the correct/expected props values.

Is this a bug?

@jcowles
Copy link
Author

jcowles commented Feb 19, 2023

@jcowles
Copy link
Author

jcowles commented Feb 19, 2023

Actually, my issue was solved by including the physics type in the key:

<RigidBody
    key={props.physicsType + props.index}

@jcowles jcowles closed this as completed Feb 19, 2023
@jcowles
Copy link
Author

jcowles commented Feb 19, 2023

After thinking about this a bit more, I think this is a hack/workaround - this is just forcing react to create a new tracking object when the state changes, but really props.index alone (which is a stable identifier) should be enough, no?

reopening

@jcowles jcowles reopened this Feb 19, 2023
@wiledal wiledal added the bug Something isn't working label Feb 21, 2023
@wiledal
Copy link
Member

wiledal commented Feb 21, 2023

Indeed, this is intended to work! In fact there is a Demo of this working here:

https://react-three-rapier.pmnd.rs/dynamic-type-changes 🤔

However there is an odd situation that the RigidBody does not always go back from kinematicPosition to dynamic, unless the body is forced to collide with something. I believe that is a Rapier bug - but it's an odd one!

@wiledal
Copy link
Member

wiledal commented Mar 6, 2023

@dimforge/rapier3d-compat@0.12.2 had an update related to this.

Fix bug that made dynamic rigid-bodies behave like kinematic bodies after being disabled and then re-enabled.

Is this still an issue in @react-three/rapier@0.14.0?

@gregfagan
Copy link

This appears to still be happening. I can work around it with

rigidbody?.setEnabled(false);
rigidbody?.setEnabled(true);

whenever I'm changing the type. This is with @react-three/rapier at 0.15.1

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

No branches or pull requests

3 participants