AmmoJSPlugin raycast function broken;

Using the raycast function of the ammo plugin, I get the following error:

Cannot read property 'reset' of undefined
    at e.raycast (babylon.js:16)
    at index.ts:78
    at e._renderLoop (babylon.js:16)

Looks like you forgot to initialize _raycastResult @trevordev
Wouldn’t it also be nice to return copy? If you always return the same object and reset it in between, unwanted side effects might happen, if the user stores a reference to it.

@mauricedoepke, thanks for reporting, yep, do you want to create a PR to fix it, the file is here: Babylon.js/ammoJSPlugin.ts at master · BabylonJS/Babylon.js · GitHub? Else I can do it.

@bobalazek do you want to comment on the second piece? Did you do this to avoid creating multiple objects every frame? If so no change is needed.

Ok, I’ve created the PR (Ammo physics raycast fix by bobalazek · Pull Request #6125 · BabylonJS/Babylon.js · GitHub).

Yes, that’s right. You could easily have dozens or hundreds raycasts per frame - especially as I initially planned it to use with the physics effects class

1 Like