Setting Linear velocity using meshes with children is my crashing xr experience

Hello, I am trying to make some basic program, where im using cannon physics.

I have made a “tennis racket” by using parent and children, rather than merging meshes, due to collision interactions. An example of my code for this is in this playground link:
https://playground.babylonjs.com/#AVUGIA#4

if this link doesn’t take to the right page let me know and ill do it again

when i have a controller in my xr setting, i try to use mesh.physicsImpostor.setLinearVelocity(BABYLON.Vector3.Zero());
i use the tenisNet, to apply this to (tenisNet.physicsImpostor…)

when i press the button (ill put the code below the rest of the text) it crashes the xr experience.
I have used this with singular shapes with no connections and it works as expected

The code that is used for the controller is:

xr.input.onControllerAddedObservable.add((controller) => {
                    controller.onMotionControllerInitObservable.add((motionController) => {            
                        motionController.getMainComponent().onButtonStateChangedObservable.add((component) => {
                            if (component.changes.pressed) {
                                if (component.pressed) {

                                    tenisNet.position.y = 1; 

                                    tenisNet.rotationQuaternion = new BABYLON.Quaternion();

                                    tenisNet.physicsImpostor.setLinearVelocity(BABYLON.Vector3.Zero()); // this causes the xr to crash, due to it being a mesh with children         
                                }

                            }

                        });
                    })
                })

Thanks to anyone who can provide any help

pinging @RaananW

Hi!

So, this is not an XR issue, but rather code issue that will fail even not in XR.

If you are using your playground in the XR experience as well, this might be the problem:

image

You are setting the physics impostor as collisionsEnabled (which is a boolean), and later use:

tenisNet.physicsImpostor.setLinearVelocity(BABYLON.Vector3.Zero());

which is undefined. Set the physicsImpostor in the first line, and it will work as expected.

Thanks for the help it worked.

1 Like