Hello Guys,
I have a problem when rotating a car model before adding the VehicleControl to it (see attched video)
Any thoughts what might be the problem?
Thank you,
Adi
Hello Guys,
I have a problem when rotating a car model before adding the VehicleControl to it (see attched video)
Any thoughts what might be the problem?
Thank you,
Adi
My guess is that something needs to be change in the below code - when adding the wheels, I need to take in consideration the current model’s rotation. But it’s just a guess… what do you think?
float stiffness = 120.0f;//200=f1 car
float compValue = 0.2f; //(lower than damp!)
float dampValue = 0.3f;
final float mass = 400;
Spatial carNode = model.getChild(0);
carNode.setShadowMode(RenderQueue.ShadowMode.Cast);
Geometry chasis = findGeom(carNode, "Car");
BoundingBox box = (BoundingBox) chasis.getModelBound();
CollisionShape carHull = CollisionShapeFactory.createDynamicMeshShape(chasis);
VehicleControl modelCtl = new VehicleControl(carHull, mass);
model.addControl(modelCtl);
am.physicalControl = modelCtl;
//Setting default values for wheels
modelCtl.setSuspensionCompression(compValue * 2.0f * FastMath.sqrt(stiffness));
modelCtl.setSuspensionDamping(dampValue * 2.0f * FastMath.sqrt(stiffness));
modelCtl.setSuspensionStiffness(stiffness);
modelCtl.setMaxSuspensionForce(10000);
Vector3f wheelDirection = new Vector3f(0, -1, 0);
Vector3f wheelAxle = new Vector3f(-1, 0, 0);
Geometry wheel_fr = findGeom(carNode, "WheelFrontRight");
wheel_fr.center();
box = (BoundingBox) wheel_fr.getModelBound();
float wheelRadius = box.getYExtent();
float back_wheel_h = (wheelRadius * 1.7f) - 1f;
float front_wheel_h = (wheelRadius * 1.9f) - 1f;
modelCtl.addWheel(wheel_fr.getParent(), box.getCenter().add(0, -front_wheel_h, 0),
wheelDirection, wheelAxle, 0.2f, wheelRadius, true);
Geometry wheel_fl = findGeom(carNode, "WheelFrontLeft");
wheel_fl.center();
box = (BoundingBox) wheel_fl.getModelBound();
modelCtl.addWheel(wheel_fl.getParent(), box.getCenter().add(0, -front_wheel_h, 0),
wheelDirection, wheelAxle, 0.2f, wheelRadius, true);
Geometry wheel_br = findGeom(carNode, "WheelBackRight");
wheel_br.center();
box = (BoundingBox) wheel_br.getModelBound();
modelCtl.addWheel(wheel_br.getParent(), box.getCenter().add(0, -back_wheel_h, 0),
wheelDirection, wheelAxle, 0.2f, wheelRadius, false);
Geometry wheel_bl = findGeom(carNode, "WheelBackLeft");
wheel_bl.center();
box = (BoundingBox) wheel_bl.getModelBound();
modelCtl.addWheel(wheel_bl.getParent(), box.getCenter().add(0, -back_wheel_h, 0),
wheelDirection, wheelAxle, 0.2f, wheelRadius, false);
modelCtl.getWheel(2).setFrictionSlip(4);
modelCtl.getWheel(3).setFrictionSlip(4);
bulletAppState.getPhysicsSpace().add(modelCtl);
I’m kind of stuck with this. Something goes wrong with the wheel axel when adding the wheel to the VehicleControl. I’m not sure if it’s a bug in the VehicleControl or I’m doing something wrong
i were not using VehicleControl, but i assume your rotation break some of your center of mass for wheels. Because as i see the wheels are rotating, but local model geometry is like not in center.
check local translation for your wheels.
I found a workaround:
The problem was that first:
I switched the flow:
Thanks
Adi