private bool PerformCollisionWander(Companion companion, GameTime time) { this.behaviorTimer -= time.ElapsedGameTime.Milliseconds; if (this.behaviorTimer >= 0) { companion.Halt(); companion.motion.Value = Vector2.Zero; return(false); } companion.motion.Value = Vector2.One; int targetDirection = companion.FacingDirection; if (Game1.random.NextDouble() < 0.007) { int newDirection = Game1.random.Next(5); if (newDirection != (companion.FacingDirection + 2) % 4) { if (newDirection < 4) { companion.Halt(); targetDirection = newDirection; if (companion.currentLocation.isCollidingPosition(companion.nextPosition(newDirection), Game1.viewport, companion)) { companion.SetMovingDirection(companion.previousDirection); this.behaviorTimer = Game1.random.Next(2000, 10000); return(false); } companion.previousDirection.Value = companion.FacingDirection; companion.SetMovingDirection(targetDirection); } } } Location next_tile = companion.nextPositionTile(); if (!companion.currentLocation.isTileOnMap(new Vector2(next_tile.X, next_tile.Y)) || companion.currentLocation.isCollidingPosition(companion.nextPosition(targetDirection), Game1.viewport, isFarmer: true, 0, glider: false, companion, pathfinding: false)) { companion.SetMovingDirection(companion.facingDirection); this.behaviorTimer = Game1.random.Next(2000, 10000); if (Game1.random.NextDouble() < 0.6) { companion.SetMovingDirection(Utility.GetOppositeFacingDirection(companion.facingDirection)); } } else { switch (targetDirection) { case 0: companion.position.Y -= companion.speed; break; case 1: companion.position.X += companion.speed; break; case 2: companion.position.Y += companion.speed; break; case 3: companion.position.X -= companion.speed; break; } } return(false); }