I have a similar problem to the other thread, my UFO does tilts but I only want it to tilt a little and now it is overrotating.
[java] public void onAnalog(String name, float value, float tpf) {
int speed = 20000 * 80000;
if (name.equals(“rotateRight”) && rotate) {
ufoNode.rotate(0, 1 * tpf, 0);
}
if (name.equals(“rotateLeft”) && rotate) {
ufoNode.rotate(0, -1 * tpf, 0);
}
if (name.equals(“rotateUp”) && rotate) {
ufoNode.rotate(0, 0, -1 * tpf);
}
if (name.equals(“rotateDown”) && rotate) {
ufoNode.rotate(0, 0, 1 * tpf);
}
Vector3f camDir = cam.getDirection().clone().multLocal(speed * tpf);
Vector3f camUp = cam.getUp().clone().mult(speed * tpf);
camDir.y = 0;
ufoDirection.set(0, 0, 0);
Vector3f xRotation = ufoControl.getPhysicsRotation()
.getRotationColumn(0).normalize();
Vector3f yRotation = ufoControl.getPhysicsRotation()
.getRotationColumn(1).normalize();
Vector3f zRotation = ufoControl.getPhysicsRotation()
.getRotationColumn(2).normalize();
Vector3f rotate = new Vector3f();
if (name.equals(“moveLeft”)) {
ufoDirection.set(cam.getLeft().multLocal(speed * tpf));
if (ufoControl.getAngularVelocity().getZ() < 0.2f) {
// ufoControl.applyTorque(zRotation.mult(speed));
} else // if (ufoControl.getAngularVelocity().getZ() >- 0.2f)
{
// ufoControl.applyTorque(zRotation.mult(2peed).negate());
}
}
if (name.equals(“moveRight”)) {
ufoDirection.set(cam.getLeft()).multLocal(-speed * tpf);
// ufoControl.applyTorque(zRotation.mult(speed).negate());
}
if (name.equals(“moveForward”)) {
ufoDirection.set(camDir);
}
if (name.equals(“moveBackward”)) {
ufoDirection.set(camDir.multLocal(-1f));
}
if (name.equals(“moveUp”)) {
ufoDirection.addLocal(camUp);
}
if (name.equals(“moveDown”)) {
ufoDirection.addLocal(cam.getUp().multLocal(-speed * tpf));
}
ufoControl.applyCentralForce(ufoDirection);
}[/java]
If I use applyTorque, then I don’t have a good way of slowing the rotation when keeping moving left for instance. I tried making a custom control but the prephysicstick method is not called, why not?
[java]
public class UFOBodyControl extends RigidBodyControl implements
PhysicsTickListener {
public UFOBodyControl() {
super();
// bulletAppState.getPhysicsSpace().addCollisionListener(this);
}
public UFOBodyControl(CollisionShape shape) {
super(shape);
}
public UFOBodyControl(CollisionShape shape, float mass) {
super(shape, mass);
}
public UFOBodyControl(CylinderCollisionShape shape, float f) {
super(shape, f);
System.out.println("UFOBodyControl");
}
@Override
public void prePhysicsTick(PhysicsSpace space, float tpf) {
// apply state changes ...
System.out.println("prePhysicsTick" + this.getAngularVelocity());
setAngularVelocity(Vector3f.ZERO);
}
@Override
public void physicsTick(PhysicsSpace arg0, float arg1) {
// TODO Auto-generated method stub
System.out.println("physicsTick" + this.getAngularVelocity());
}
}
[/java]
How can I control the spaceship from overrotating?