[SOLVED] applyLocalTorque in PlayCanvas

Hi, I wanted to apply torque locally to my player. But PlayCanvas doesn’t seem to have an applyLocalTorque function. But it seems ammojs does support it.

I tried to understand how to call ammojs functions from PlayCanvas but I found it a bit complicated. This is what I used:

I would appreciate it if anyone can help me figure this out.


Hi @Gamer_Wael,

I think that method is available in the internal Ammo.js body object, you can find a reference to it like this:


Try it and let us know if that works.

Thanks for the reply.

Unfortunately, it doesn’t seem to be working.

This works fine:


But this doesn’t:


Chances are that it’s expecting an Ammo.btVector3 type.


this.player.rigidbody.body.applyLocalTorque(new Ammo.btVector3(0, 0, 5));

I recommend looking at the engine source for more examples on using Ammo directly: https://github.com/playcanvas/engine/blob/master/src/framework/components/rigid-body/component.js

A list of exposed functions are here: https://github.com/kripken/ammo.js/blob/master/ammo.idl


@yaustar I think that is the latest IDL. Is it used by Playcanvas? Is there a place where one may check the bindings of the Ammo version used by PC?

Honestly, not sure which version we are tracking. If in doubt grab the latest from the Ammo repo.

1 Like

Right, unfortunately it is not as easy, because the version that is used by Playcanvas is using a special feature (Ammo.addFunction) which is not enabled in the default build, available in Ammo repository. One would need to download the sources, set up emscripten and build with a compilation flag that enables it.

@will Which version of Ammo are we using these days? AFAIK, we are not maintaining our own private fork.

Correct. We just use the latest build directly from the master ammo.js repo maintained by kripken.

@will @yaustar
Thank you for the response. So, I think the pre-built version in kripken’s repository is older than the latest IDL bindings file. Nevertheless, I downloaded the pre-built Ammo files from the build folder in the repository and added to Playcanvas project. Here is the result:

Project is private :slight_smile:

Fixed :slight_smile:

Odd, looking at the commit history on Ammo, it should be there :thinking:

I think the way the callbacks are handled was changed. If you are referring to the addFunction commit for the test, then the test was changed: