Problems using Havok raycast

Hi, I am trying to use the Havok plugin to perform raycasting in my project. I used the following documentation:

  1. Babylon.js docs
  2. Babylon.js docs

There are a few problems I am running in to. First of all, it seems like the raycastToRef method does not exist on my physicsEngine. It only has the raycast method available. I am not sure exactly what is the difference between the two and if it matters which one I use. Second, when calling the raycast method with a start and end Vector3 as input, I get the following error:

My code is as follows:

const havokInstance = await HavokPhysics();
const hk = new HavokPlugin(true, havokInstance);
scene.enablePhysics(new Vector3(0, -9.8, 0), hk);

const physicsEngine = scene.getPhysicsEngine();
let res = physicsEngine?.raycast(Vector3.Zero(), new Vector3(1, 1, 1));
console.log(res);

I’ve searched across the web for this error, but barely any search results show up and I have not been able to find similar problems on the forum here. I am using BabylonJS v6.10.0 and I installed Havok using the npm package @babylonjs/havok.

On the playground it seems to work as intended: Babylon.js Playground

Hi @Luca , welcome to the forum!

In Babylon.js, the difference between a function and the same function with ToRef suffix means the ToRef will put the result into the result parameter instead of returning a new value.
This way, garbage collection will not recycle new values from time to time. So, when you can, use the ToRef version as much as you can. It’s a good practice.

Documentation is in sync with the laster release npm. 6.10.0 is quite old now. I suggest you to update to 7.25+

2 Likes

Thanks for the detailed response! Upgrading to 7.26.2 fixed this.

1 Like