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>(); }
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>(); }
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); }