I've tested this a bit and seems to work...mostly. The spin-out is pretty good. I found that 50 is the best %impulse value to use in terms of spin-out effect and maintaining vehicle collision norms.
What we really need for this to work well is a way to apply a new rotation without affecting the vehicle's position. Setting %vehicle.rotation to the new rotation doesn't seem to do anything. Until we can find a way to affect rotation without using %vehicle.setTransform(), I don't think this is possible to do well.
function startspinout(%vehicle,%timeinseconds,%impactvector,%impulse)
{
if(isObject(%vehicle) && %vehicle.getClassName() $= "WheeledVehicle")
{
schedule(%timeinseconds * 1000,0,"stopspinout",%vehicle);
%vehicle.eulerRot = 1;
%vehicle.impulsedecline = %impulse / %timeinseconds / 100;
%vehicle.spinout = 1;
%vehicle.setTransform(%vehicle.position SPC eulerToAxis(getWords(axisToEuler(getWords(%vehicle.getTransform(),3,6)),0,1) SPC %vehicle.eulerRot));
%velX = getWord(%impactVector,0) * %impulse + getWord(%vehicle.getVelocity(),0);
%velY = getWord(%impactVector,1) * %impulse + getWord(%vehicle.getVelocity(),1);
%velZ = getWord(%vehicle.getVelocity(),2);
%vehicle.setVelocity(%velX SPC %velY SPC %velZ);
schedule(10,0,"continuespinout",%vehicle,%impactvector,%impulse - %vehicle.impulsedecline);
}
}
function continuespinout(%vehicle,%impactvector,%impulse)
{
if(isObject(%vehicle) && %vehicle.getClassName() $= "WheeledVehicle")
{
if(%vehicle.eulerRot < 359)
{
%vehicle.eulerRot += 1;
}
else
{
%vehicle.eulerRot = 0;
}
%vehicle.setVelocity("0 0" SPC getWord(%vehicle.getVelocity(),2));
%vehicle.setTransform(%vehicle.position SPC eulerToAxis(getWords(axisToEuler(getWords(%vehicle.getTransform(),3,6)),0,1) SPC mCeil(%vehicle.eulerRot)));
%velX = getWord(%impactVector,0) * %impulse + getWord(%vehicle.getVelocity(),0);
%velY = getWord(%impactVector,1) * %impulse + getWord(%vehicle.getVelocity(),1);
%velZ = getWord(%vehicle.getVelocity(),2);
%vehicle.setVelocity(%velX SPC %velY SPC %velZ);
if(%vehicle.spinout)
{
schedule(10,0,"continuespinout",%vehicle,%impactvector,%impulse - %vehicle.impulsedecline);
}
}
}
function stopspinout(%vehicle)
{
if(isObject(%vehicle) && %vehicle.getClassName() $= "WheeledVehicle")
{
%vehicle.spinout = "";
%vehicle.eulerRot = "";
%vehicle.impulsedecline = "";
}
}