applyForce sideways to vehicle ( TestHoveringTank )

I modifing the TestHoveringTank. I wanted to add “Strifing” functionality, so I apply some force on left direction in onAnalog. With normal RigidBodyControl it is working, but probably not with vehicle.

[java]
public void onAnalog(String name, float value, float tpf) {
if (name.equals(“LeftStrife”)) {
hoverControl.SideStrife=1.0f;
hoverControl.getPhysicsRotation().getRotationColumn(0, vtemp);
hoverControl.applyForce( vtemp.multLocal( 100.0f), Vector3f.ZERO );
System.out.println( "LeftStrife "+vtemp );
return;
}
if (name.equals(“RightStrife”)) {
hoverControl.SideStrife=1.0f;
hoverControl.getPhysicsRotation().getRotationColumn(0, vtemp);
hoverControl.applyForce( vtemp.multLocal( -100.0f), Vector3f.ZERO );
System.out.println( "RightStrife "+vtemp );
return;
}

}[/java]

So I tried to modify the PhysicsHoverControl like this

[java]
public void prePhysicsTick(PhysicsSpace space, float f) {
Vector3f angVel = getAngularVelocity();
float rotationVelocity = angVel.getY();
Vector3f dir = getForwardVector(tempVect2).multLocal(1, 0, 1).normalizeLocal();
getLinearVelocity(tempVect3);
Vector3f linearVelocity = tempVect3.multLocal(1, 0, 1);

    if (steeringValue != 0) {
        if (rotationVelocity < 1 && rotationVelocity > -1) {
            applyTorque(tempVect1.set(0, steeringValue, 0));
        }
    } else {
        // counter the steering value!
        if (rotationVelocity > 0.2f) {
            applyTorque(tempVect1.set(0, -mass * 20, 0));
        } else if (rotationVelocity < -0.2f) {
            applyTorque(tempVect1.set(0, mass * 20, 0));
        }
    }
	
	
    if (accelerationValue > 0) {
        float d = dir.dot(linearVelocity.normalize());
        Vector3f counter = dir.project(linearVelocity).normalizeLocal().negateLocal().multLocal(1 - d);
        applyForce(counter.multLocal(mass * 10), Vector3f.ZERO);

        if (linearVelocity.length() < 30) {
            applyForce(dir.multLocal(accelerationValue), Vector3f.ZERO);
	//getPhysicsRotation().getRotationColumn(2, tempVect4);                                     // I tried also put it here - it does something,                                                           
	//applyForce(tempVect4.multLocal(accelerationValue*0.01f), Vector3f.ZERO);    // but never move really sideways  
        }
    } else {
        // counter the acceleration value
        if (linearVelocity.length() > FastMath.ZERO_TOLERANCE) {
            linearVelocity.normalizeLocal().negateLocal();
            applyForce(linearVelocity.mult(mass * 10), Vector3f.ZERO);
        }
    }

  //=============== THIS WHAT I ADD =================
	if (FastMath.abs(SideStrife)>0.0001f){
		getPhysicsRotation().getRotationColumn(0, tempVect4);
		applyForce( tempVect4.multLocal( 1000.0f*SideStrife), Vector3f.ZERO );
		SideStrife*=0.99f;
		System.out.println( "SideStrife applyForce "+SideStrife+" "+tempVect4 );
	}
}

[/java]

but neither this is working ( the vehicle does not move sideways )

OK, I’m really just an idiot. Now in the morning I got up, and try that with clean mind… the problem was just that mass of Howercraft is very big, so I have to apply force ~10000

Sorry for that
I would delete this topic If I can…

1 Like