Learn more about collision machines and what you can use them for.
Collision machines are Unity components that are added to game objects. They’re mostly used for game mechanics involving collisions, like a projectile hitting a target.
A collision machine component can be added through the components menu (Makinom > Machines > Collision Machine) or the scene wizard (Add Machine > Collision Machine). A game object with a collision machine is represented in the Unity scene view by this gizmo icon:
You can learn more about machine components in general and their basic settings here.
Start Types #
A collision machine is started when a game object collides with the machine’s game object. This requires collider and rigidbody components on the game objects.
By default, collision machines can only be started when colliding with the player’s game object. Optionally, they can also be started by other game objects – this can further limited to game objects with a defined name, tag or component attached.
Collision Enter #
Started when another game object starts colliding with the machine’s game object. It’s implemented in the component’s OnCollisionEnter and OnCollisionEnter2D functions.
Local Start Variables #
This start type will automatically initialize the following local variables.
- relativeVelocity (Vector3)
Stores the relative linear velocity of the two game objects. - normal (Vector3 list)
Stores the normals of the contact points. - point (Vector3 list)
Stores the points (positions) of the contact points.
Additional Start Conditions #
The Collision Enter start type can optionally be limited by a layer mask. This can be used to only start the machine when colliding with game objects of a defined layer.
Example #
This start type can be used to let an explosive barrel explode when hit by a projectile. Use a Spawn Prefab node to spawn a particle effect prefab and a Play Sound node to play an audio clip.
Collision Stay #
Started while another game object continues colliding with the machine’s game object. It’s implemented in the component’s OnCollisionStay and OnCollisionStay2D functions.
Local Start Variables #
This start type will automatically initialize the following local variables.
- relativeVelocity (Vector3)
Stores the relative linear velocity of the two game objects. - normal (Vector3 list)
Stores the normals of the contact points. - point (Vector3 list)
Stores the points (positions) of the contact points.
Additional Start Conditions #
The Collision Stay start type can optionally be limited by a layer mask. This can be used to only start the machine when colliding with game objects of a defined layer.
Example #
This start type can be used to play particle effects on the contact points while colliding. Use a Spawn Prefab node to spawn a particle effect prefab, using the local Vector3 variable list point for the contact points.
Collision Exit #
Started when another game object stops colliding with the machine’s game object. It’s implemented in the component’s OnCollisionExit and OnCollisionExit2D functions.
Local Start Variables #
This start type will automatically initialize the following local variables.
- relativeVelocity (Vector3)
Stores the relative linear velocity of the two game objects. - normal (Vector3 list)
Stores the normals of the contact points. - point (Vector3 list)
Stores the points (positions) of the contact points.
Additional Start Conditions #
The Collision Stay start type can optionally be limited by a layer mask. This can be used to only start the machine when colliding with game objects of a defined layer.
Example #
This start type can be used to add force to a rigidbody after a collision. Use one of the Rigidbody nodes (e.g. a Rigidbody Explosion Force node) to add force to a game object’s rigidbody.
Particle Collision #
Started when a particle collides with the machine’s game object. It’s implemented in the component’s OnParticleCollision function.
Additional Start Conditions #
The Collision Stay start type can optionally be limited by a layer mask. This can be used to only start the machine when colliding with game objects of a defined layer.
Example #
This start type can be used to damage enemies or the player (i.e. reducing a health variable) through particles. Use a Change Variables node to change the health variable.
Controller Collider Hit #
Started when a character controller collides with the machine’s game object or a game object collides with the machine’s character controller – both require the character controller to perform a move in that frame. It’s implemented in the component’s OnControllerColliderHit function.
Local Start Variables #
This start type will automatically initialize the following local variables.
- moveLength (float)
Stores how far the character controller has traveled before colliding. - moveDirection (Vector3)
Stores direction the characer controller was moving in when colliding. - normal (Vector3)
Stores the normal of collision point. - point (Vector3)
Stores the collision point (position).
Additional Start Conditions #
The Collision Stay start type can optionally be limited by a layer mask. This can be used to only start the machine when colliding with game objects of a defined layer.
Example #
This start type can be used to push game objects out of the way of the character controller. Use one of the Rigidbody nodes (e.g. a Rigidbody Change Velocity node) to move a game object through it’s rigidbody.