예제 #1
0
        public Agent(CoreEngine c, Vector3 position, Vector2 direction)
        {
            core           = c;
            this.position  = position;
            this.direction = direction;
            equipped       = new Pistol();

            agentVelocities = new Velocities();
            collisionCells  = new List <CollisionGridCell>();
        }
예제 #2
0
        public Agent(CoreEngine c, Vector3 position, Vector2 direction)
        {
            core = c;
            this.position = position;
            this.direction = direction;
            equipped = new Pistol();

            agentVelocities = new Velocities();
            collisionCells = new List<CollisionGridCell>();
        }
예제 #3
0
        public void applyMovement(float elapsedTime, Agent player, Vector3 velocity)
        {
            BoundingBox playerBoundingBox = player.getBoundingBox();

            //update the persistentVelocity
            Velocities pv = player.agentVelocities;

            if (pv.persistentVelocity.Y == 0)
            {
                pv.persistentVelocity.Y = velocity.Y;
            }
            velocity.Y = 0;
            pv.persistentVelocity.Y += -gravity * elapsedTime;

            //fix it to ensure terminalVelcoity
            if (pv.persistentVelocity.Y <= player.terminalVelocity)
            {
                pv.persistentVelocity.Y = player.terminalVelocity;
            }

            Vector3 retMove = (velocity) * elapsedTime;

            Vector3 offset = center(playerBoundingBox) - player.getPosition();

            Vector3 playerRadius = size(playerBoundingBox) * 0.5f;
            Vector3 basePoint    = toESpace(playerRadius, center(playerBoundingBox));
            Vector3 evelocity    = toESpace(playerRadius, retMove);

            Vector3 pos = collideWithWorld(playerRadius, basePoint, evelocity, 0, player);

            Vector3 eSpacePersistent = toESpace(playerRadius, pv.persistentVelocity);
            Vector3 finalPos         = collideWithWorld(playerRadius, pos, eSpacePersistent, 0, player);
            //Vector3 finalPos = collideWithWorld(playerRadius, pos, Vector3.Zero, 0);

            //check if we're on the floor
            //this happens if we were moving down and the velocity vector was modified
            Vector3 eSpaceActualMove = finalPos - pos;

            if (eSpacePersistent.Y < 0 && eSpaceActualMove.Y - 0.005 > eSpacePersistent.Y)
            {
                pv.persistentVelocity.Y = 0;
                finalPos = pos;
            }
            if (eSpacePersistent.Y > 0 && eSpaceActualMove.Y + 0.005 < eSpacePersistent.Y)
            {
                pv.persistentVelocity.Y = -0.005f;
            }

            player.setPosition(toWorldSpace(playerRadius, finalPos) - offset);
        }