private CarMotor m_Car; // the car motor we want to use private void Awake() { m_Rigidbody = GetComponent <Rigidbody>(); m_Car = new CarMotor(); m_Car.SetCarMovementInterface(this); m_Car.InitializeCarMotor(m_CentreOfMassOffset, m_MaximumSteerAngle, m_SteerHelper, m_TractionControl, m_FullTorqueOverAllWheels, m_ReverseTorque, m_Topspeed, m_RevRangeBoundary, m_SlipLimit, m_BrakeTorque); m_Car.SetCarAudioInterface(this); m_Car.InitializeCarAudio(lowPitchMin, lowPitchMax); m_Car.StartSound(); }
private CarMotor m_Car; // the car motor we want to use private void Awake() { m_Rigidbody = GetComponent<Rigidbody>(); m_Car = new CarMotor(); m_Car.SetCarMovementInterface(this); m_Car.InitializeCarMotor(m_CentreOfMassOffset, m_MaximumSteerAngle, m_SteerHelper, m_TractionControl, m_FullTorqueOverAllWheels, m_ReverseTorque, m_Topspeed, m_RevRangeBoundary, m_SlipLimit, m_BrakeTorque); m_Car.SetCarAudioInterface(this); m_Car.InitializeCarAudio(lowPitchMin, lowPitchMax); m_Car.StartSound(); }
public void InitializeCarMotor() { //Arrange CarMotor car = new CarMotor(); var movement = GetMovementMock(); car.SetCarMovementInterface(movement); Vector3 CoM = new Vector3(1, 1, 1); //Act car.InitializeCarMotor(CoM, 25f, 0.7f, 0.5f, 2500f, 500f, 100f, 1f, 0.3f, 20000f); //Assert movement.Received().SetWheelColliderCenterOfMass(CoM); }
public void MoveDidApplyHandbrake() { //Arrange CarMotor car = new CarMotor(); var movement = GetMovementMock(); car.SetCarMovementInterface(movement); //Act car.Move(0, 0, 0, 1); //Assert movement.Received().ApplyHandBrake(Arg.Any <float>()); // we should see the velocity being reset }
public void MoveClamping() { //Arrange CarMotor car = new CarMotor(); var movement = GetMovementMock(); car.SetCarMovementInterface(movement); car.InitializeCarMotor(new Vector3(0, 0, 0), 25f, 0.7f, 0.5f, 2500f, 500f, 100f, 1f, 0.3f, 20000f); //Act car.Move(0, 25, -25, 0); //Assert Assert.AreEqual(1f, car.AccelInput); Assert.AreEqual(-1f, -car.BrakeInput); }
public void MoveAddDownforce() { //Arrange CarMotor car = new CarMotor(); var movement = GetMovementMock(); car.SetCarMovementInterface(movement); float dF = (float)GetInstanceField(typeof(CarMotor), car, "m_Downforce"); //Act car.Move(0, 0, 0, 1); //Assert movement.Received().AddDownForce(dF); // we should see the velocity being reset }
public void MoveApplyDrive() { //Arrange CarMotor car = new CarMotor(); var movement = GetMovementMock(); car.SetCarMovementInterface(movement); car.InitializeCarMotor(new Vector3(0, 0, 0), 25f, 0.7f, 0.5f, 2500f, 500f, 100f, 1f, 0.3f, 20000f); float t = (float)GetInstanceField(typeof(CarMotor), car, "m_CurrentTorque"); float accel = 0.5f; //Act car.Move(0, accel, 0, 0); //Assert movement.Received().ApplyMotorTorque(accel * t / 4); // t in this case is the total torque over all 4 wheels so divide by 4 }
public void MoveRotateTires() { //Arrange CarMotor car = new CarMotor(); var movement = GetMovementMock(); car.SetCarMovementInterface(movement); car.InitializeCarMotor(new Vector3(0, 0, 0), 25f, 0.7f, 0.5f, 2500f, 500f, 100f, 1f, 0.3f, 20000f); float maxSteerAngle = (float)GetInstanceField(typeof(CarMotor), car, "m_MaximumSteerAngle"); float steering = 0.5f; //Act car.Move(steering, 0, 0, 0); //Assert movement.Received().RotateFrontTires(steering * maxSteerAngle); }
public void MoveCapSpeed() { //Arrange CarMotor car = new CarMotor(); var movement = GetMovementMock(); movement.GetRigidbodyVelocity().Returns(100f); // this will return a velocity magnitude equal to our top speed variable car.SetCarMovementInterface(movement); float topSpeed = 100f; car.InitializeCarMotor(new Vector3(0, 0, 0), 25f, 0.7f, 0.5f, 2500f, 500f, topSpeed, 1f, 0.3f, 20000f); float mphConst = (float)GetInstanceField(typeof(CarMotor), car, "k_MphConst"); //Act car.Move(0, 1, 0, 0); //Assert movement.Received().SetRigidbodyVelocity(topSpeed / mphConst); // we should see the velocity being reset }
public void MoveCheckForWheelSpinEndTrail() { //Arrange CarMotor car = new CarMotor(); var movement = GetMovementMock(); movement.GetWheelColliderForwardSlip(Arg.Any <int>()).Returns(0); // less then slip limit movement.GetWheelColliderSidewaysSlip(Arg.Any <int>()).Returns(0); // less then slip limit car.SetCarMovementInterface(movement); float slipLimit = 0.3f; car.InitializeCarMotor(new Vector3(0, 0, 0), 25f, 0.7f, 0.5f, 2500f, 500f, 100f, 1f, slipLimit, 20000f); //Act car.Move(0, 0, 0, 1); //Assert movement.Received(4).EndSkidTrail(Arg.Any <int>()); // we should the skid trail ending 4 times }
public void MoveCheckForWheelSpinTireSmoke() { //Arrange CarMotor car = new CarMotor(); var movement = GetMovementMock(); movement.GetWheelColliderForwardSlip(Arg.Any <int>()).Returns(1); // more then slip limit movement.GetWheelColliderSidewaysSlip(Arg.Any <int>()).Returns(1); // more then slip limit car.SetCarMovementInterface(movement); float slipLimit = 0.3f; car.InitializeCarMotor(new Vector3(0, 0, 0), 25f, 0.7f, 0.5f, 2500f, 500f, 100f, 1f, slipLimit, 20000f); //Act car.Move(0, 0, 0, 1); //Assert movement.Received(4).EmitTireSmoke(Arg.Any <int>()); // we should the tire smoke emitted 4 times }
public void MoveCheckForWheelSpinTireSmoke() { //Arrange CarMotor car = new CarMotor(); var movement = GetMovementMock(); movement.GetWheelColliderForwardSlip(Arg.Any<int>()).Returns(1); // more then slip limit movement.GetWheelColliderSidewaysSlip(Arg.Any<int>()).Returns(1); // more then slip limit car.SetCarMovementInterface(movement); float slipLimit = 0.3f; car.InitializeCarMotor(new Vector3(0, 0, 0), 25f, 0.7f, 0.5f, 2500f, 500f, 100f, 1f, slipLimit, 20000f); //Act car.Move(0, 0, 0, 1); //Assert movement.Received(4).EmitTireSmoke(Arg.Any<int>()); // we should the tire smoke emitted 4 times }
public void MoveCheckForWheelSpinEndTrail() { //Arrange CarMotor car = new CarMotor(); var movement = GetMovementMock(); movement.GetWheelColliderForwardSlip(Arg.Any<int>()).Returns(0); // less then slip limit movement.GetWheelColliderSidewaysSlip(Arg.Any<int>()).Returns(0); // less then slip limit car.SetCarMovementInterface(movement); float slipLimit = 0.3f; car.InitializeCarMotor(new Vector3(0, 0, 0), 25f, 0.7f, 0.5f, 2500f, 500f, 100f, 1f, slipLimit, 20000f); //Act car.Move(0, 0, 0, 1); //Assert movement.Received(4).EndSkidTrail(Arg.Any<int>()); // we should the skid trail ending 4 times }
public void MoveDidApplyHandbrake() { //Arrange CarMotor car = new CarMotor(); var movement = GetMovementMock(); car.SetCarMovementInterface(movement); //Act car.Move(0, 0, 0, 1); //Assert movement.Received().ApplyHandBrake(Arg.Any<float>()); // we should see the velocity being reset }
public void MoveCapSpeed() { //Arrange CarMotor car = new CarMotor(); var movement = GetMovementMock(); movement.GetRigidbodyVelocity().Returns(100f); // this will return a velocity magnitude equal to our top speed variable car.SetCarMovementInterface(movement); float topSpeed = 100f; car.InitializeCarMotor(new Vector3(0, 0, 0), 25f, 0.7f, 0.5f, 2500f, 500f, topSpeed, 1f, 0.3f, 20000f); float mphConst = (float)GetInstanceField(typeof(CarMotor), car, "k_MphConst"); //Act car.Move(0, 1, 0, 0); //Assert movement.Received().SetRigidbodyVelocity(topSpeed/mphConst); // we should see the velocity being reset }