Teleporting an entity relative to itself when the entity type is unknown

I would like to know how I can teleport an entity relative to itself if the entity type is unknown. I have tried the solution in this topic here: Teleport all entities relative to themselves in 1.13 removing the type=minecart part leaving just @e, but that just ends up making all the entities cram themselves together. The command I used was:

execute at @p run execute as @e[distance=..15,type=!player] at @s run tp @e[type=!player,distance=..15] ^ ^10 ^

Solution 1:

Your old command:

execute
  at @p                                       # At the nearest player...
  as @e[distance=..15,type=!player]           # give control to all non-players within 15 blocks and make them...
  at @s                                       # move the execution position to themselves and...
run tp @e[type=!player,distance=..15] ^ ^10 ^ # teleport all the entities 10 blocks up from themselves

The last part is the problem. When each entity runs /tp, they are referencing all the entities, causing them all to teleport to the same position. You need each entity to reference themselves independently, which means changing the target selector in the /tp to @s.

execute at @p as @e[distance=..15,type=!player] at @s run tp @s ~ ~10 ~

Explanation:

execute
  at @p                             # At the nearest player...
  as @e[distance=..15,type=!player] # give control to all non-players within 15 blocks and make them...
  at @s                             # move the execution position to themselves and...
run tp @s ~ ~10 ~                   # teleport themselves upward ten blocks

I changed the ^s to ~s because they are more reliable when teleporting entities, that way they aren't sightline-sensitive.