private void CreateCharacter() { Broadphase.OverlappingPairCache.SetInternalGhostPairCallback(new GhostPairCallback()); const float characterHeight = 1.75f; const float characterWidth = 1.75f; var capsule = new CapsuleShape(characterWidth, characterHeight); GhostObject = new PairCachingGhostObject() { CollisionShape = capsule, CollisionFlags = CollisionFlags.CharacterObject, WorldTransform = Matrix.Translation(10.210098f, -1.6433364f, 16.453260f) }; World.AddCollisionObject(GhostObject, CollisionFilterGroups.CharacterFilter, CollisionFilterGroups.StaticFilter | CollisionFilterGroups.DefaultFilter); const float stepHeight = 0.35f; Character = new KinematicCharacterController(GhostObject, capsule, stepHeight); World.AddAction(Character); }
private void CreateVehicle(Matrix transform) { var chassisShape = new BoxShape(1.0f, 0.5f, 2.0f); var compound = new CompoundShape(); //localTrans effectively shifts the center of mass with respect to the chassis Matrix localTrans = Matrix.Translation(Vector3.UnitY); compound.AddChildShape(localTrans, chassisShape); RigidBody carChassis = PhysicsHelper.CreateBody(800, Matrix.Identity, compound, World); carChassis.UserObject = "Chassis"; //carChassis.SetDamping(0.2f, 0.2f); var tuning = new VehicleTuning(); var vehicleRayCaster = new DefaultVehicleRaycaster(World); //vehicle = new RaycastVehicle(tuning, carChassis, vehicleRayCaster); _vehicle = new CustomVehicle(tuning, carChassis, vehicleRayCaster); carChassis.ActivationState = ActivationState.DisableDeactivation; World.AddAction(_vehicle); const float connectionHeight = 1.2f; // choose coordinate system _vehicle.SetCoordinateSystem(rightIndex, upIndex, forwardIndex); Vector3 wheelDirection = Vector3.Zero; Vector3 wheelAxle = Vector3.Zero; wheelDirection[upIndex] = -1; wheelAxle[rightIndex] = -1; bool isFrontWheel = true; var connectionPoint = new Vector3(CUBE_HALF_EXTENTS - (0.3f * wheelWidth), connectionHeight, 2 * CUBE_HALF_EXTENTS - wheelRadius); _vehicle.AddWheel(connectionPoint, wheelDirection, wheelAxle, suspensionRestLength, wheelRadius, tuning, isFrontWheel); connectionPoint = new Vector3(-CUBE_HALF_EXTENTS + (0.3f * wheelWidth), connectionHeight, 2 * CUBE_HALF_EXTENTS - wheelRadius); _vehicle.AddWheel(connectionPoint, wheelDirection, wheelAxle, suspensionRestLength, wheelRadius, tuning, isFrontWheel); isFrontWheel = false; connectionPoint = new Vector3(-CUBE_HALF_EXTENTS + (0.3f * wheelWidth), connectionHeight, -2 * CUBE_HALF_EXTENTS + wheelRadius); _vehicle.AddWheel(connectionPoint, wheelDirection, wheelAxle, suspensionRestLength, wheelRadius, tuning, isFrontWheel); connectionPoint = new Vector3(CUBE_HALF_EXTENTS - (0.3f * wheelWidth), connectionHeight, -2 * CUBE_HALF_EXTENTS + wheelRadius); _vehicle.AddWheel(connectionPoint, wheelDirection, wheelAxle, suspensionRestLength, wheelRadius, tuning, isFrontWheel); for (int i = 0; i < _vehicle.NumWheels; i++) { WheelInfo wheel = _vehicle.GetWheelInfo(i); wheel.SuspensionStiffness = suspensionStiffness; wheel.WheelsDampingRelaxation = suspensionDamping; wheel.WheelsDampingCompression = suspensionCompression; wheel.FrictionSlip = wheelFriction; wheel.RollInfluence = rollInfluence; } _vehicle.RigidBody.WorldTransform = transform; }