⚙️ method Bot.Attack(...)

Last updated:4/16/2026

URL

https://github.com/42core-team/monorepo/blob/dev/bots/go/client_lib/actions.go

Description

Attacks a target with a unit.

This action not only used to damage any object, but it's also good for destroying deposits, picking up gem piles & lighting a bomb's fuse.

⚠️ There is friendly fire - you can damage your own units and core. So BE CAREFUL!
  • Units can only attack one tile up, down, left or right; for more see Action Position Limits.
  • Units can only attack if their action cooldown is 0, for more see Cooldowns.

Signature

func (b *Bot) Attack(attacker, target *game.Object)

Parameters

  • attacker *game.Object: The unit that should attack
  • target *game.Object: The object the unit should attack

Return

void (nil-safe: does nothing if either argument is nil)

Examples

target := getTarget(g)
unit := getAttackerUnit(g)
 
if g.Distance(unit.Pos, target.Pos) <= 1 && target.IsEnemy(g.MyTeamID) {
	b.Attack(unit, target)
}