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.
m_linearSleepingThreshold = linear;
m_angularSleepingThreshold = angular;
}
void applyTorque(const btVector3& torque)
{
m_totalTorque += torque*m_angularFactor;
}
// XXX AMMO local addition to bullet
void applyLocalTorque(const btVector3& torque)
{
m_totalTorque += m_worldTransform.getBasis() * torque * m_angularFactor;
}
void applyForce(const btVector3& force, const btVector3& rel_pos)
{
applyCentralForce(force);
applyTorque(rel_pos.cross(force*m_linearFactor));
}
I tried to understand how to call ammojs functions from PlayCanvas but I found it a bit complicated. This is what I used:
https://developer.playcanvas.com/en/user-manual/physics/calling-ammo/
I would appreciate it if anyone can help me figure this out.
Thanks.
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:
this.entity.rigidbody.body.applyLocalTorque(50,0,0);
Try it and let us know if that works.
Thanks for the reply.
Unfortunately, it doesn’t seem to be working.
This works fine:
this.player.rigidbody.applyTorque(0,0,5);
But this doesn’t:
this.player.rigidbody.body.applyLocalTorque(0,0,5);
yaustar
November 13, 2020, 10:52am
4
Chances are that it’s expecting an Ammo.btVector3 type.
Try:
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
3 Likes
LeXXik
November 13, 2020, 10:58am
5
@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?
yaustar
November 13, 2020, 11:14am
6
Honestly, not sure which version we are tracking. If in doubt grab the latest from the Ammo repo.
1 Like
LeXXik
November 13, 2020, 1:09pm
7
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.
yaustar
November 13, 2020, 1:53pm
8
@will Which version of Ammo are we using these days? AFAIK, we are not maintaining our own private fork.
will
November 13, 2020, 1:56pm
9
Correct. We just use the latest build directly from the master ammo.js repo maintained by kripken.
LeXXik
November 13, 2020, 2:01pm
10
@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:
https://playcanvas.com/editor/scene/1032122
yaustar
November 13, 2020, 2:12pm
13
Odd, looking at the commit history on Ammo, it should be there
LeXXik
November 13, 2020, 2:21pm
14
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: