//Got no propellers. Derp.
if(numProps == 0)
break;
Vector3f up = axes.getYAxis();
throttleScaled *= numPropsWorking / numProps * 2F;
float upwardsForce = throttle * throttleScaled + (g - throttleScaled / 2F);
if(throttle < 0.5F)
upwardsForce = g * throttle * 2F;
if(!isPartIntact(EnumDriveablePart.blades))
{
upwardsForce = 0F;
}
//Move up
//Throttle - 0.5 means that the positive throttle scales from -0.5 to +0.5. Thus it accounts for gravity-ish
motionX += upwardsForce * up.x * 0.5F;
motionY += upwardsForce * up.y;
motionZ += upwardsForce * up.z * 0.5F;
//Apply gravity
motionY -= g;
//Apply wobble
//motionX += rand.nextGaussian() * wobbleFactor;
//motionY += rand.nextGaussian() * wobbleFactor;
//motionZ += rand.nextGaussian() * wobbleFactor;
//Apply drag
motionX *= drag;
motionY *= drag;
motionZ *= drag;
break;
case PLANE :
//Count the number of working propellers
for(Propeller prop : type.propellers)
if(isPartIntact(prop.planePart))
numPropsWorking++;
numProps = type.propellers.size();
//Got no propellers. Derp.
if(numProps == 0)
break;
//Apply forces
Vector3f forwards = (Vector3f)axes.getXAxis().normalise();
//Sanity limiter
if(lastTickSpeed > 2F)
lastTickSpeed = 2F;
float newSpeed = lastTickSpeed + throttleScaled * 2F;
//Calculate the amount to alter motion by
float proportionOfMotionToCorrect = 2F * throttle - 0.5F;
if(proportionOfMotionToCorrect < 0F)
proportionOfMotionToCorrect = 0F;
if(proportionOfMotionToCorrect > 0.5F)
proportionOfMotionToCorrect = 0.5F;
//Apply gravity
g = 0.98F / 20F;
motionY -= g;
//Apply lift
int numWingsIntact = 0;
if(isPartIntact(EnumDriveablePart.rightWing)) numWingsIntact++;
if(isPartIntact(EnumDriveablePart.leftWing)) numWingsIntact++;
float amountOfLift = 2F * g * throttle * numWingsIntact / 2F;
if(amountOfLift > g)
amountOfLift = g;
motionY += amountOfLift;
//Cut out some motion for correction
motionX *= 1F - proportionOfMotionToCorrect;
motionY *= 1F - proportionOfMotionToCorrect;
motionZ *= 1F - proportionOfMotionToCorrect;
//Add the corrected motion
motionX += proportionOfMotionToCorrect * newSpeed * forwards.x;
motionY += proportionOfMotionToCorrect * newSpeed * forwards.y;
motionZ += proportionOfMotionToCorrect * newSpeed * forwards.z;
//Apply drag
motionX *= drag;
motionY *= drag;
motionZ *= drag;
break;
default:
break;
}
for(EntityWheel wheel : wheels)
{
if(wheel != null && worldObj != null)
if(type.floatOnWater && worldObj.isAnyLiquid(wheel.boundingBox))
{
motionY += type.buoyancy;
}
}
//Move the wheels first
for(EntityWheel wheel : wheels)
{
if(wheel != null)
{
wheel.prevPosY = wheel.posY;
wheel.moveEntity(motionX, motionY, motionZ);
}
}
//Update wheels
for(int i = 0; i < 2; i++)
{
Vector3f amountToMoveCar = new Vector3f(motionX / 2F, motionY / 2F, motionZ / 2F);
for(EntityWheel wheel : wheels)
{
if(wheel == null)
continue;
//Hacky way of forcing the car to step up blocks
onGround = true;
wheel.onGround = true;
//Update angles
wheel.rotationYaw = axes.getYaw();
//Pull wheels towards car
Vector3f targetWheelPos = axes.findLocalVectorGlobally(getPlaneType().wheelPositions[wheel.ID].position);
Vector3f currentWheelPos = new Vector3f(wheel.posX - posX, wheel.posY - posY, wheel.posZ - posZ);
float targetWheelLength = targetWheelPos.length();
float currentWheelLength = currentWheelPos.length();
float dLength = targetWheelLength - currentWheelLength;
float dAngle = Vector3f.angle(targetWheelPos, currentWheelPos);
//if(dLength > 0.01F || dAngle > 1F)
{
//Now Lerp by wheelSpringStrength and work out the new positions
float newLength = currentWheelLength + dLength * type.wheelSpringStrength;
Vector3f rotateAround = Vector3f.cross(targetWheelPos, currentWheelPos, null);
Matrix4f mat = new Matrix4f();
mat.m00 = currentWheelPos.x;
mat.m10 = currentWheelPos.y;
mat.m20 = currentWheelPos.z;
mat.rotate(dAngle * type.wheelSpringStrength, rotateAround);
axes.rotateGlobal(-dAngle * type.wheelSpringStrength, rotateAround);
Vector3f newWheelPos = new Vector3f(mat.m00, mat.m10, mat.m20);
newWheelPos.normalise().scale(newLength);
//The proportion of the spring adjustment that is applied to the wheel. 1 - this is applied to the plane
float wheelProportion = 0.75F;
//wheel.motionX = (newWheelPos.x - currentWheelPos.x) * wheelProportion;
//wheel.motionY = (newWheelPos.y - currentWheelPos.y) * wheelProportion;
//wheel.motionZ = (newWheelPos.z - currentWheelPos.z) * wheelProportion;
Vector3f amountToMoveWheel = new Vector3f();
amountToMoveWheel.x = (newWheelPos.x - currentWheelPos.x) * (1F - wheelProportion);
amountToMoveWheel.y = (newWheelPos.y - currentWheelPos.y) * (1F - wheelProportion);
amountToMoveWheel.z = (newWheelPos.z - currentWheelPos.z) * (1F - wheelProportion);