In this version of Torque3D MIT (v3.6.1) there is still the problem of aircraft getting stuck in terrain or other objects. such as when you land an aircraft at low speeds and it slowly drifts into a wall and "Gets Stuck". These code tweaks will help to automatically "UNSTICK" your stuck aircraft. using your editor add these dynamic values into your vehicle datablock: lastColVec = 0 0 0
lastColVecB = 1 1 1
unstickMeter = 0 in your scripts: scripts / server / vehicle.cs function VehicleData::onAdd(%this, %obj)
{
%obj.setRechargeRate(%this.rechargeRate);
%obj.setEnergyLevel(%this.MaxEnergy);
%obj.setRepairRate(0);
if (%obj.mountable || %obj.mountable $= "")
%this.isMountable(%obj, true);
else
%this.isMountable(%obj, false);
if (%this.nameTag !$= "")
%obj.setShapeName(%this.nameTag);
if (%obj.getClassName() $= "FlyingVehicle")
%this.CheckForStuck(%obj);
}because it tends to occur with only flying vehicles, adding in if (%obj.getClassName() == "FlyingVehcile") will make it apply only to flying vehicles. %this.CheckForStuck(%obj); is the call that will start it's routine checking for getting stuck, and pushing the vehicle back when a sticky situation is detected. these values are managed by the onCollision and onImapct functions: function VehicleData::onCollision(%this, %obj, %sourceObject, %position, %len)
{
%tempPosition = %obj.getPosition();
if (%obj.lastColVec !$= %tempPosition)
{
%obj.lastColVecB = %obj.lastColVec;
%obj.lastColVec = %tempPosition;
}
} function VehicleData::onImpact(%this, %obj, %sourceObject, %position, %len)
{
%tempPosition = %obj.getPosition();
if (%obj.lastColVec !$= %tempPosition)
{
%obj.lastColVecB = %obj.lastColVec;
%obj.lastColVec = %tempPosition;
}
} during any contact with another object - collision or full impact speed - the position the the craft will now be stored in the datablock. this will provide "Rewind" values. We will get to that later. For now, add in the function that does the actual hard work: function VehicleData::CheckForStuck(%this,%obj)
{
//Make sure this vehicle still exists. return if it doesn't.
if(!isObject(%obj) )
{
return;
}
%Vehiclepos = %obj.getPosition();
if (%Vehiclepos $= %obj.UnstickPosition)
{
// the vehicle is stuck!?!
// let it check a couple more times on our sticky meeter to make sure.
%obj.unstickMeter = %obj.unstickMeter + 1;
if (%obj.unstickMeter > 2)
{
// echo (" ============== ATTEMPTING TO UNSTICK! ---");
if (%obj.unstickMeter > 5)
{
// UNSTICK IS NOT WORKING!
// you may wish to add code to destroy the vehicle or kill the player at this point.
%obj.unstickMeter = 5;
}
// let's check our two history variables for a previous nearby collision
// and set vehicle back to that position.
// it will either bump lose quickly or "Shake" loose.
if (%vehiclepos $= %obj.lastColVec)
{
%newPosition = %obj.lastColVecB;
}
else
{
%newPosition = %obj.lastColVec;
}
// echo ("Unstick Attempt - change " @ %vehiclepos @ " to " @ %newPosition);
%obj.setTransform(%newPosition));
}
}
else
{
%obj.unstickMeter = 0;
%obj.unstickPosition = %VehiclePos;
}
if ( isObject(%obj) )
{
// decrease the 250 to a lower number for a faster response to sticking but more burden on the server / hosting client.
%this.schedule(250,CheckForStuck,%obj);
}
else
{
// at some point during this function the vehicle was removed or destroyed.
// echo("\c1 Vehicle::: DESTROYED!");
}
} i find this working on aircraft datablocks with the following values: bodyRestitution = 1 bodyFriction = 0.1 collisionTol = 1 contactTol = 1 this is intended only for vehicles that have a minimum speed > 0 (even if they are just wiggling in place) this is not a "TRUE" solution or a perfect fix, but it does make getting stuck MUCH more rare and with some tweaking you may get better results.