public static TankStateInfo CalcPosInFutureWithRequestedDir(Vector2 _requestDir, float timeInSecs, TankStateInfo tankInfo, out List <Vector2> passedPos) { TankStateInfo resultInfo = new TankStateInfo(tankInfo); Vector2 requestDir = _requestDir; float elapsedTime = 0; float dt = Time.fixedDeltaTime; List <Vector2> allPos = new List <Vector2>(); allPos.Add(resultInfo.Pos); while (elapsedTime <= timeInSecs) { elapsedTime += dt; int[] powerChange = AIUtility.CalcPowerChangeBasedOnRequestDir(requestDir, resultInfo); resultInfo.LeftCurPower = powerChange[0]; resultInfo.RightCurPower = powerChange[1]; // Pos update { Vector2 f = TankUtility.CalcAppliedLinearForce(resultInfo); float m = resultInfo.Mass; float drag = resultInfo.LinearDrag; Vector2 a = f / m; resultInfo.LinearVel = (resultInfo.LinearVel + a * dt) * (1f / (1f + drag * dt)); resultInfo.Pos += resultInfo.LinearVel * dt; allPos.Add(resultInfo.Pos); } // rot update { float torque = TankUtility.CalcAppliedTorque(resultInfo); float angularDrag = resultInfo.AngularDrag; float angularAccel = torque / resultInfo.Inertia * Mathf.Rad2Deg; resultInfo.AngularVel = (resultInfo.AngularVel + angularAccel * dt) * (1f / (1f + angularDrag * dt)); float rotDiff = resultInfo.AngularVel * dt; resultInfo.Rot += rotDiff; requestDir = requestDir.Rotate(rotDiff); } } passedPos = allPos; return(resultInfo); }
public void PerformActuation(Vector2 requestDir) { int[] powerChange = AIUtility.CalcPowerChangeBasedOnRequestDir(requestDir, new TankStateInfo(this)); this.Hull.PerformPowerChange(powerChange[0], powerChange[1]); }