Eye of the Nile Docs
Everything you need to know to get started!
Loading...
Searching...
No Matches
SoftCollider Class Reference

Detailed Description

Used in the Soft Collider.prefab, which is put as a child onto other objects. Allows for other objects to pass through this object, but push them out if they stay inside this object.

For example, a player can pass through a pot or an enemy, but will be pushed away if they try to stand inside it. Think of how animals in Minecraft push each other around when there's too many in a small area.

Documentation updated 9/15/2024

Author
Roy Pascual
Note
Only applies to objects on the "Push" layer.

Properties

Rigidbody2D ParentBody [get, set]
 Reference to the rigidbody of the parent object.
 

Private Member Functions

void OnTriggerEnter2D (Collider2D collision)
 Runs when an object enters the soft collider. Adds any new opposing colliders to the opposingColliders list.

Parameters
collision

 
void OnTriggerStay2D (Collider2D collision)
 Runs every frame an object is in the soft collider. Calculate and apply momentum to each object in opposingColliders that pushes them away from this object.

Parameters
collisionRepresents the object colliding with the SoftCollider hitbox.

 
void OnTriggerExit2D (Collider2D collision)
 Runs when an object exits the soft collider. Remove any leaving opposing colliders from the opposingColliders list.

Parameters
collision

 
void Awake ()
 Initialize ParentBody and opposingColliders.
 

Private Attributes

List< SoftCollideropposingColliders
 List of all objects colliding with the parent object.
 
float pushMagnitude = 3f
 How much the opposing colliders should be pushed away.
 

Member Function Documentation

◆ Awake()

void SoftCollider.Awake ( )
private

Initialize ParentBody and opposingColliders.

◆ OnTriggerEnter2D()

void SoftCollider.OnTriggerEnter2D ( Collider2D collision)
private

Runs when an object enters the soft collider. Adds any new opposing colliders to the opposingColliders list.

Parameters
collision

◆ OnTriggerExit2D()

void SoftCollider.OnTriggerExit2D ( Collider2D collision)
private

Runs when an object exits the soft collider. Remove any leaving opposing colliders from the opposingColliders list.

Parameters
collision

◆ OnTriggerStay2D()

void SoftCollider.OnTriggerStay2D ( Collider2D collision)
private

Runs every frame an object is in the soft collider. Calculate and apply momentum to each object in opposingColliders that pushes them away from this object.

Parameters
collisionRepresents the object colliding with the SoftCollider hitbox.

Member Data Documentation

◆ opposingColliders

List<SoftCollider> SoftCollider.opposingColliders
private

List of all objects colliding with the parent object.

◆ pushMagnitude

float SoftCollider.pushMagnitude = 3f
private

How much the opposing colliders should be pushed away.

Property Documentation

◆ ParentBody

Rigidbody2D SoftCollider.ParentBody
getset

Reference to the rigidbody of the parent object.


The documentation for this class was generated from the following file: