Exemplo n.º 1
0
        public void UpdateAction(CollisionWorld collisionWorld, float deltaTimeStep)
        {
            _findGroundAndSteps.Reset();
            collisionWorld.ContactTest(RigidBody, _findGroundAndSteps);
            OnGround      = _findGroundAndSteps.HaveGround;
            _groundNormal = _findGroundAndSteps.GroundNormal;

            UpdateVelocity(deltaTimeStep);
            if (_stepping || _findGroundAndSteps.HaveStep)
            {
                if (!_stepping)
                {
                    _steppingTo        = _findGroundAndSteps.StepPoint;
                    _steppingInvNormal = _findGroundAndSteps.getInvNormal();
                }
                StepUp(deltaTimeStep);
            }

            if (OnGround || _stepping)
            {
                /* Avoid going down on ramps, if already on ground, and clearGravity()
                 * is not enough */
                RigidBody.Gravity = Vector3.Zero;
            }
            else
            {
                RigidBody.Gravity = _gravity;
            }
        }
Exemplo n.º 2
0
        void FixedUpdate()
        {
            objsCurrentlyInContactWith.Clear();
            world.ContactTest(rigidBody, contactCallback);

            //TODO see if there is a way to do this without needing to allocate two HashSets every FixeUpdate
            //TODO think about efficiency. things won't change much most of the FixedUpdate calls. Using these sets may be overkill
            //TODO can probably arrays if less than 4 total collisions in previous and current and use hashsets if more.

            //enter collisions
            HashSet <SingleCollision> enterObjects = new HashSet <SingleCollision>(objsCurrentlyInContactWith, new SingleCollisionComparer());

            enterObjects.ExceptWith(objsIWasInContactWithLastFrame);
            //exit collisions
            HashSet <SingleCollision> exitObjects = new HashSet <SingleCollision>(objsIWasInContactWithLastFrame, new SingleCollisionComparer());

            exitObjects.ExceptWith(objsCurrentlyInContactWith);
            //stay collisions
            objsCurrentlyInContactWith.ExceptWith(enterObjects);

            foreach (SingleCollision o in enterObjects)
            {
                BOnCollisionEnter(o);
            }

            foreach (SingleCollision o in objsCurrentlyInContactWith)
            {
                BOnCollisionStay(o);
            }

            foreach (SingleCollision o in exitObjects)
            {
                BOnCollisionExit(o);
            }

            objsIWasInContactWithLastFrame.Clear();
            objsIWasInContactWithLastFrame.UnionWith(enterObjects);
            objsIWasInContactWithLastFrame.UnionWith(objsCurrentlyInContactWith);
        }