public void ManageAI(MovementAI ai, Rigidbody2D character) { Kinematic characterKinematic = KinematicAdapter.FromRigidbody2DToKinematic(character); Kinematic targetKinematic = new Kinematic(); Algorithm algorithm = new KinematicNone(); switch (ai.aiAlgorithm) { case AIAlgorithm.KinematicSeek: targetKinematic = KinematicAdapter.FromRigidbody2DToKinematic(ai.target); algorithm = new KinematicSeek(characterKinematic, targetKinematic, ai.maxSpeed); break; case AIAlgorithm.KinematicFlee: targetKinematic = KinematicAdapter.FromRigidbody2DToKinematic(ai.target); algorithm = new KinematicFlee(characterKinematic, targetKinematic, ai.maxSpeed); break; case AIAlgorithm.KinematicArrive: targetKinematic = KinematicAdapter.FromRigidbody2DToKinematic(ai.target); algorithm = new KinematicArrive(characterKinematic, targetKinematic, ai.maxSpeed, ai.satisfactionRadius, ai.timeToTarget); break; case AIAlgorithm.KinematicWander: algorithm = new KinematicWander(characterKinematic, ai.maxSpeed, ai.maxRotation); break; } SteeringOutput steering = algorithm.getSteering(); steering.Apply(characterKinematic, ai.lookWhereYoureGoing, ai.maxSpeed, Time.deltaTime); KinematicAdapter.UpdateRigidbody2DWithKinematic(character, characterKinematic); }
public void ManageAI(MovementAI ai, Rigidbody2D character) { Kinematic characterKinematic = KinematicAdapter.FromRigidbody2DToKinematic(character); Kinematic targetKinematic = new Kinematic(); Algorithm algorithm = new DynamicNone(); switch (ai.aiAlgorithm) { case AIAlgorithm.DynamicSeek: targetKinematic = KinematicAdapter.FromRigidbody2DToKinematic(ai.target); algorithm = new DynamicSeek(characterKinematic, targetKinematic, ai.maxSpeed); break; case AIAlgorithm.DynamicFlee: targetKinematic = KinematicAdapter.FromRigidbody2DToKinematic(ai.target); algorithm = new DynamicFlee(characterKinematic, targetKinematic, ai.maxSpeed); break; case AIAlgorithm.DynamicArrive: targetKinematic = KinematicAdapter.FromRigidbody2DToKinematic(ai.target); algorithm = new DynamicArrive(characterKinematic, targetKinematic, ai.maxAcceleration, ai.maxSpeed, ai.targetRadius, ai.slowRadius, ai.timeToTarget); break; case AIAlgorithm.DynamicAlign: targetKinematic = KinematicAdapter.FromRigidbody2DToKinematic(ai.target); algorithm = new DynamicAlign(characterKinematic, targetKinematic, ai.maxRotation, ai.maxAngularAcceleration, ai.targetRadius, ai.slowRadius, ai.timeToTarget); break; case AIAlgorithm.DynamicVelocityMatch: targetKinematic = KinematicAdapter.FromRigidbody2DToKinematic(ai.target); algorithm = new DynamicVelocityMatch(characterKinematic, targetKinematic, ai.maxAcceleration, ai.timeToTarget); break; } SteeringOutput steering = algorithm.getSteering(); steering.Apply(characterKinematic, ai.lookWhereYoureGoing, ai.maxSpeed, Time.deltaTime); KinematicAdapter.UpdateRigidbody2DWithKinematic(character, characterKinematic); }