diff --git a/scripts/ai/include/attack_generic.lua b/scripts/ai/include/attack_generic.lua
index 81873e8..59c9eb7 100644
--- a/scripts/ai/include/attack_generic.lua
+++ b/scripts/ai/include/attack_generic.lua
@@ -56,7 +56,7 @@ function atk_g()
     atk_g_ranged(target, dist)
 
   elseif dist > range * atk_aim then
-    if ai.relvel(target) < 0 then
+    if ai.relvel(target) > -10 then
       atk_g_ranged(target, dist)
     else
       atk_g_aim(target, dist)
@@ -110,6 +110,7 @@ end
 function atk_g_melee(target, dist)
   secondary, special = ai.secondary("melee")
   dir = ai.aim(target) -- We aim instead of face.
+  range = ai.getweaprange()
 
   -- Fire non-smart secondary weapons.
   if(secondary == "Launcher" and special ~= "Smart") or
@@ -119,6 +120,12 @@ function atk_g_melee(target, dist)
     end
   end
 
+  -- Drifting away we'll want to get closer.
+  if dir < 10 and dist > 0.5*range and ai.relvel(target) > -10 then
+    ai.accel()
+  end
+
+  -- Shoot if should be shooting.
   if(dir < 10 and dist < range) or ai.hasturrets() then
     ai.shoot()
   end