Hey Monkeys
I made a Kart class based on the TestFancyCar example but when I start the Game the Cart and the wheels are leike screwed up or just go to the center of the Chasis.
Here’s the Kart class:
[java]package kartGame;
import com.jme3.asset.AssetManager;
import com.jme3.bounding.BoundingBox;
import com.jme3.bullet.collision.shapes.CollisionShape;
import com.jme3.bullet.control.VehicleControl;
import com.jme3.bullet.util.CollisionShapeFactory;
import com.jme3.math.FastMath;
import com.jme3.math.Vector3f;
import com.jme3.renderer.queue.RenderQueue.ShadowMode;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
/**
*
-
@author elias
*/
public class Kart {
private float stiffness = 120.0f;//200=f1 car
private float compValue = 0.2f; //(lower than damp!)
private float dampValue = 0.3f;
private float mass;
private float wheelRadius;
private float steeringValue = 0;
private float accelerationValue = 0;
private VehicleControl vehicleControl;
private Node kartNode;
public Kart(AssetManager assetManager,String fileName){
mass = 400;
kartNode = (Node)assetManager.loadModel(fileName);
kartNode.setShadowMode(ShadowMode.Cast);
Geometry chasis = findGeom(kartNode,“Chasis”);
BoundingBox box = (BoundingBox) chasis.getModelBound();
//Create a hull collision shape for the chassis
CollisionShape carHull = CollisionShapeFactory.createDynamicMeshShape(chasis);
//Create a vehicle control
vehicleControl = new VehicleControl(carHull, mass);
kartNode.addControl(vehicleControl);
//Setting default values for wheels
vehicleControl.setSuspensionCompression(compValue * 2.0f * FastMath.sqrt(stiffness));
vehicleControl.setSuspensionDamping(dampValue * 2.0f * FastMath.sqrt(stiffness));
vehicleControl.setSuspensionStiffness(stiffness);
vehicleControl.setMaxSuspensionForce(10000);
//Create four wheels and add them at their locations
//note that our fancy car actually goes backwards…
Vector3f wheelDirection = new Vector3f(Vector3f.UNIT_Y); //maybe her’s the problem I tried to change the Vector units but on any
Vector3f wheelAxle = new Vector3f(Vector3f.UNIT_X);//logicol combination wierd things happen to the wheels.
Geometry wheel_fr = findGeom(kartNode, “WheelFrontRight”);
wheel_fr.center();
box = (BoundingBox) wheel_fr.getModelBound();
wheelRadius = box.getYExtent();
float back_wheel_h = (wheelRadius * 1.7f) - 1f;
float front_wheel_h = (wheelRadius * 1.9f) - 1f;
vehicleControl.addWheel(wheel_fr.getParent(), box.getCenter().add(0, -front_wheel_h, 0),
wheelDirection, wheelAxle, 0.2f, wheelRadius, true);
Geometry wheel_fl = findGeom(kartNode, “WheelFrontLeft”);
wheel_fl.center();
box = (BoundingBox) wheel_fl.getModelBound();
vehicleControl.addWheel(wheel_fl.getParent(), box.getCenter().add(0, -front_wheel_h, 0),
wheelDirection, wheelAxle, 0.2f, wheelRadius, true);
Geometry wheel_br = findGeom(kartNode, “WheelBackRight”);
wheel_br.center();
box = (BoundingBox) wheel_br.getModelBound();
vehicleControl.addWheel(wheel_br.getParent(), box.getCenter().add(0, -back_wheel_h, 0),
wheelDirection, wheelAxle, 0.2f, wheelRadius, false);
Geometry wheel_bl = findGeom(kartNode, “WheelBackLeft”);
wheel_bl.center();
box = (BoundingBox) wheel_bl.getModelBound();
vehicleControl.addWheel(wheel_bl.getParent(), box.getCenter().add(0, -back_wheel_h, 0),
wheelDirection, wheelAxle, 0.2f, wheelRadius, false);
vehicleControl.getWheel(2).setFrictionSlip(4);
vehicleControl.getWheel(3).setFrictionSlip(4);
}
public static Geometry findGeom(Spatial spatial, String name) {
if (spatial instanceof Node) {
Node node = (Node) spatial;
for (int i = 0; i < node.getQuantity(); i++) {
Spatial child = node.getChild(i);
Geometry result = findGeom(child, name);
if (result != null) {
return result;
}
}
} else if (spatial instanceof Geometry) {
if (spatial.getName().startsWith(name)) {
return (Geometry) spatial;
}
}
return null;
}
public VehicleControl getVehicleControl(){
return this.vehicleControl;
}
public float getSteeringValue(){
return this.steeringValue;
}
public void setSteeringValue(float steeringValue){
this.steeringValue = steeringValue;
}
public float getAccelerationValue(){
return this.accelerationValue;
}
public void setAccelerationValue(float accelerationValue){
this.accelerationValue = accelerationValue;
}
public float getMass(){
return this.mass;
}
public void setMass(float mass){
this.mass = mass;
}
public Node getNode(){
return this.kartNode;
}
}[/java]
Since I can’t use the SceneComposer I can’t look up the real axises of the wheels but I think the Blender importer just swaps the Y and Z direction ,doesn’t it?
Please help! I’m actually doing this project just to get a bit involved in jME but now I’m already working about that for about 4 days and 3 nights and still nothing playable came out.
Cheers
Elias