/// <summary> /// Initializes the BRaycastVehicle. /// </summary> private void Awake() { rigidBody = GetComponent <BRigidBody>(); if (rigidBody == null) { Destroy(this); return; } RaycastRobot = new RaycastRobot(defaultVehicleTuning = new VehicleTuning { MaxSuspensionForce = 1000f, MaxSuspensionTravelCm = SuspensionToleranceCm, SuspensionDamping = 10f, SuspensionCompression = SuspensionCompressionRatio, SuspensionStiffness = CalculateStiffness(DefaultNumWheels), FrictionSlip = 2f }, (RigidBody)rigidBody.GetCollisionObject(), new BRobotRaycaster((DynamicsWorld)BPhysicsWorld.Get().world)); RaycastRobot.SetCoordinateSystem(0, 1, 2); BRobotManager.Instance.RegisterRaycastRobot(RaycastRobot); }
/// <summary> /// Adds a wheel to the BRaycastVehicle from the given information. /// </summary> /// <param name="connectionPoint"></param> /// <param name="axle"></param> /// <param name="suspensionRestLength"></param> /// <param name="radius"></param> /// <returns></returns> public int AddWheel(WheelType wheelType, BulletSharp.Math.Vector3 connectionPoint, BulletSharp.Math.Vector3 axle, float suspensionRestLength, float radius) { float slidingFriction = DefaultSlidingFriction; switch (wheelType) { case WheelType.MECANUM: slidingFriction = 0.1f; axle = (Quaternion.AngleAxis((connectionPoint.X > 0 && connectionPoint.Z > 0) || (connectionPoint.X < 0 && connectionPoint.Z < 0) ? -45 : 45, Vector3.up) * axle.ToUnity()).ToBullet(); break; case WheelType.OMNI: slidingFriction = 0.1f; break; } RobotWheelInfo wheel = RaycastRobot.AddWheel(connectionPoint, -BulletSharp.Math.Vector3.UnitY, axle, suspensionRestLength, radius, defaultVehicleTuning, false); wheel.RollInfluence = RollInfluence; wheel.SlidingFriction = slidingFriction; return(RaycastRobot.NumWheels - 1); }
/// <summary> /// Updates each wheel's position for proper interpolation. /// </summary> private void Update() { for (int i = 0; i < RaycastRobot.NumWheels; i++) { RaycastRobot.UpdateWheelTransform(i, true); } }
public void DeregisterRaycastRobot(RaycastRobot raycastRobot) { if (raycastRobots.Contains(raycastRobot)) { raycastRobots.Remove(raycastRobot); } }
public void RegisterRaycastRobot(RaycastRobot raycastRobot) { if (!raycastRobots.Contains(raycastRobot)) { raycastRobots.Add(raycastRobot); } }
/// <summary> /// Adds a wheel to the BRaycastVehicle from the given information. /// </summary> /// <param name="connectionPoint"></param> /// <param name="axle"></param> /// <param name="suspensionRestLength"></param> /// <param name="radius"></param> /// <returns></returns> public int AddWheel(WheelType wheelType, BulletSharp.Math.Vector3 connectionPoint, BulletSharp.Math.Vector3 axle, float suspensionRestLength, float radius) { switch (wheelType) { case WheelType.MECANUM: RaycastRobot.SlidingFriction = 0.1f; axle = (Quaternion.AngleAxis((connectionPoint.X > 0 && connectionPoint.Z > 0) || (connectionPoint.X < 0 && connectionPoint.Z < 0) ? -45 : 45, Vector3.up) * axle.ToUnity()).ToBullet(); break; case WheelType.OMNI: RaycastRobot.SlidingFriction = 0.1f; break; } WheelInfo w = RaycastRobot.AddWheel(connectionPoint, -BulletSharp.Math.Vector3.UnitY, axle, suspensionRestLength, radius, vehicleTuning, false); w.RollInfluence = 0.25f; w.Brake = (RollingFriction / radius) * RaycastRobot.OverrideMass * BRaycastWheel.MassTorqueScalar; return(RaycastRobot.NumWheels - 1); }