示例#1
0
        protected override void OnAttach()
        {
            NativeCollisionObject = new BulletSharp.PairCachingGhostObject
            {
                CollisionShape = ColliderShape.InternalShape,
                UserObject     = this,
            };

            NativeCollisionObject.CollisionFlags |= BulletSharp.CollisionFlags.CharacterObject;

            if (ColliderShape.NeedsCustomCollisionCallback)
            {
                NativeCollisionObject.CollisionFlags |= BulletSharp.CollisionFlags.CustomMaterialCallback;
            }

            NativeCollisionObject.ContactProcessingThreshold = !Simulation.CanCcd ? 1e18f : 1e30f;

            BulletSharp.Math.Vector3 unitY = new BulletSharp.Math.Vector3(0f, 1f, 0f);
            KinematicCharacter = new BulletSharp.KinematicCharacterController((BulletSharp.PairCachingGhostObject)NativeCollisionObject, (BulletSharp.ConvexShape)ColliderShape.InternalShape, StepHeight, ref unitY);

            base.OnAttach();

            FallSpeed = fallSpeed;
            MaxSlope  = maxSlope;
            JumpSpeed = jumpSpeed;
            Gravity   = gravity;

            UpdatePhysicsTransformation(); //this will set position and rotation of the collider

            Simulation.AddCharacter(this, (CollisionFilterGroupFlags)CollisionGroup, CanCollideWith);
        }