Not sure if that correspond, but setting it to :
X: clamp(Objective.X, ViewportLeft(Self.LayerName)+Self.Width, ViewportRight(Self.LayerName)-Self.Width)
y: clamp(Objective.Y, ViewportTop(Self.LayerName)+Self.Height, ViewportBottom(Self.LayerName)-Self.Height),
Should put it on the objective unless it is offscreen, in that case it will be at the same X or Y, but stay on the border of the screen