neu5
June 12, 2022, 12:58pm
1
Hey, I was following the demo
Just a little demo of using AmmoJS natively while also using the impostor system, as there are no BabylonJS specific features to create vehicles yet, as far as I know.
https://playground.babylonjs.com/#609QKP#2
and as mentioned in Friction not being applied to vehicle · Issue #282 · kripken/ammo.js · GitHub
the driving vehicle is not slowing down.
Does anyone know how to apply friction to the vehicle with AmmoJS?
Or is it better to go with Babylon physics for simple car driving game?
cc @Cedric and @RaananW our Physix folks
2 Likes
Cedric
June 13, 2022, 1:08pm
3
Hi @neu5
Did you try to set m_rollingFriction
on the body?
// Dynamics
[Prefix="btRigidBody::"]
interface btRigidBodyConstructionInfo {
void btRigidBodyConstructionInfo(float mass, btMotionState motionState, btCollisionShape collisionShape, [Ref] optional btVector3 localInertia);
attribute float m_linearDamping;
attribute float m_angularDamping;
attribute float m_friction;
attribute float m_rollingFriction;
attribute float m_restitution;
attribute float m_linearSleepingThreshold;
attribute float m_angularSleepingThreshold;
attribute boolean m_additionalDamping;
attribute float m_additionalDampingFactor;
attribute float m_additionalLinearDampingThresholdSqr;
attribute float m_additionalAngularDampingThresholdSqr;
attribute float m_additionalAngularDampingFactor;
};
Another way that should work easily is to get the angular velocity of the wheel and reapply it with a damping. something like:
newVelocity = previousFrameVelocity * 0.99;
4 Likes
neu5
June 13, 2022, 2:30pm
4
Hey @Cedric ,
Thanks for replying.
I tried every kind of friction with no luck
Doing it by hand feels somehow hacky to me
But maybe I’ll give it a try
Hello!
I don’t know if I get your question right, the problem is that your car is not slowing down after releasing the gas pedal?
What I’ve done is added breaking when we don’t press the forwards, or backwards buttons:
else if(!actions.acceleration && !actions.braking){
breakingForce += 0.03*dt
}
neu5
June 14, 2022, 3:10pm
6
Hello @Matthias22 .
Thanks for sharing the idea. It feels hacky to me too but maybe I’ll try it.
I was reading the topic
I’ve taken the bit and parts and ported them over one by one. If I remember correctly, very few, if any, changes are needed to make it work.
In the castRay function of your raycaster, you simply put:
rayCallback.m_collisionFilterMask = collisionFilterMask;
rayCallback.m_collisionFilterGroup = collisionFilterGroup;
Before you do the rayTest.
So between setting the result callback and calling the rayTest function. Then it’s automatically handled.
Then you just need a way of setting your mas…
and I was wondering if the friction is not working out of the box and some digging in the AmmoJS code (custom build?) is required?
@Raggar maybe you will know?