Skip to main content

On Collision With Do

Tells the "owner" of the block what to do when it bumps into an agent of the selected breed. The "owner" is an agent of the breed whose page is where this collision block is put.

On Collision With Do block

Description

The On Collision With Do block tells the "owner" of the block what to do when it bumps into an agent of the selected breed. The "owner" is an agent of the breed whose page is where this collision block is put. This is a code block from the Detection drawer.

Usage

On Collision With Do begins the execution of a stack of code when a collision is detected with a specific type of agent denoted in the drop down selector. The agent collided with is known as the "collidee". This agent can be referenced using the collidee block.

Syntax

Inputs:

  • A breed from the dropdown menu
  • Relevant code to execute on collision
On Collision With Do syntax

Example

When the fish prey agents collide with the whale predator agent (i.e. they have the same x, y, and z coordinates) the prey agent deletes itself. This interaction makes it appear as if the predator eats the prey.

On Collision With Do example code

Notes

On Collision With Do cannot be used as a conditional such as if. On Collision With Do must begin a stack of code.

  • Collidee - References the agent that was collided with