Repository navigation
Trying to recreate a collision response behaviour: overriding ContactSettings #1581
Replies: 3 comments 1 reply
|
I think If you use Jolt's You could also use |
|
Thanks for the suggestions @jrouwe .
Do you think it would be easy to integrate this in to Jolt? I could try my luck but I don't know how much stuff there would be to touch to implement this |
|
Thanks for the help, like you said, by only modifying the contacts it did not seem trivial so I went with another method. class MyCollector : public CollideShapeCollector
{
public:
// Constructor
explicit MyCollector(Vec3 inVehicleFwd) : inForward(inVehicleFwd)
{
}
virtual void AddHit(const CollideShapeResult& inResult) override
{
mNormal = -inResult.mPenetrationAxis.Normalized();
// Point on the wall
mContactPoint = inResult.mContactPointOn2;
mContactPointOnVehicle = inResult.mContactPointOn1;
// Normal of which we will reflect the car's forward vector to 'reflect' the car
mFaceNormal = (inResult.mShape2Face[1] - inResult.mShape2Face[0]).Cross(inResult.mShape2Face[2] - inResult.mShape2Face[0]).Normalized();
// Reflect inForward along mFaceNormal
mReflected = inForward - 2.0f * inForward.Dot(mFaceNormal) * mFaceNormal;
}
Vec3 mNormal = Vec3::sZero();
Vec3 mFaceNormal = Vec3::sZero();
Vec3 mContactPoint = Vec3::sZero();
Vec3 mContactPointOnVehicle = Vec3::sZero();
Vec3 mReflected = Vec3::sZero();
private:
Vec3 inForward;
};Then I calculate an angular impulse to apply a rolling rotation to the vehicle Vec3 rollAxis = mBody->GetRotation() * Vec3(0, 0, 1); // Z is up
Vec3 rotationAxis = carFwd.Cross(collector.mReflected).Normalized();Then using the contact point on the vehicle and the center of mass position, I apply the impulse if the car is hitting the wall from the 'front'. This is to prevent another bounce because after reflecting once, the rear side of the vehicle might hit the wall again, causing another bounce. This is of course with, |
Uh oh!
There was an error while loading. Please reload this page.
Hello,
I'm trying to create this behaviour for my vehicle:
crash.mp4
It looks like a pretty standard/realistic collision response, however, the car never pitches up or down due to crashing into barriers, other than that it just seems to reflect the car depending on your entry angle. So I tried to modify the
ContactSettingsinside aContactListenerand managed to disable the rotation by settingmInvInertiaScale2to zero and really low friction and restitution, however I guess this also takes away your ability to utilizemRelativeAngularSurfaceVelocityas well, though I'm not really sure that's the right way to solve this. Anyway, my question is, is this doable by only modifying contacts? Another way that comes to mind is keeping the inv intertia scale 0 and keep a 'just crashed' state and apply angular impulse outside.All reactions