[SOLVED] Car wheels not displaying correctly

Hello All, I am trying to use the new vehicle physics script, it is working fine for the buggy,
but when I changed the model, the wheels are not properly displaying.

for (i = 0; i < this.vehicle.getNumWheels(); i++) {
t = this.vehicle.getWheelTransformWS(i);

    p = t.getOrigin();
    q = t.getRotation();

    this.pos.set(p.x(), p.y(), p.z());
    this.quat.set(q.x(), q.y(), q.z(), q.w());

    // convert world position to local position
    this.mat.transformPoint(this.pos, this.pos);
    // bring the wheel models a little further in
    
    this.pos.scale(100);
    this.pos.x *= 0.9;


    // position wheel models
    this.graphics.wheels[i].setLocalPosition(this.pos);
    this.graphics.wheels[i].setRotation(this.quat);

    // position wheel debug shapes
    if (this.DEBUG_DRAW) {
        this.debug.wheels[i].setPosition(p.x(), p.y(), p.z());
        this.debug.wheels[i].setRotation(this.quat);
    }
}

I saw a forum discussing about the wheels on the buggy, I cant figure out how it was fixed since it was also present in the buggy.
@yaustar @Nathan_Hawkins1 and @evandarcy , Please help me figure out the specific solution you guys applied after that forum discussion and made the wheels display correctly.

Link to the game:
https://playcanvas.com/project/648582/overview/ammo-vehicle

That script was modified for the model that was used in the thread. Start off by doing no modifications to the position, rotation or scale to the wheels.

Does it display correctly?

Yes the buggy displays correctly, but when I replaced it with lamborghini the wheels do not display correctly, the chassis are displayed correctly and everything else works fine.

Looks like a case of adding 90 rotation on the world Y axis to fix it.

Look at line 533

        this.graphics.wheels[i].setEulerAngles(angle.x,angle.y + 90,angle.z);

Get rid of the + 90. That was done specifically for the other thread’s model.

Yes I got rid of that, still wont change the result.

The vehicle functionality of bullet wasn’t really designed to be used with all in one model which is causing issues as it did with the other thread. The wheels I believe are meant to be separate models?

Yes those are separate mesh instances, being accessed through code.

As in, they were designed to be separate entities from the car. The issue is that the local transforms and parent transforms of the wheels in the model is messing up the rotations unless we reverse engineer how it was done.

If you enable DEBUG_DRAW, it shows the debug wheels being placed correctly.

image

1 Like

see debug shapes for the vehicle this.DEBUG_DRAW = 1;
vehicle.js line number 71, the debug has been set to true, so it is showing the generated colliders by the ammo physics engine. You can turn it off by making it 0.

1 Like

Hey yaustar, yes you were right, the original model had rotations applied to it,
after zeroing out the rotations and translation, I imported it again, but still it is causing
weird issues with the rotations, as it is rotating on the wrong origin, even though the origin is correctly set in 3dx max.

Project:
https://playcanvas.com/editor/scene/828707

I managed to solve it, the pivot was indeed the problem, Thanks yauster!
Link : https://playcanv.as/p/LQF1Xpnw/