0
0
Unityframework~10 mins

Particle collision in Unity - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Particle collision
Particle moves
Check collision with other particles or objects
Yes
Calculate collision response
Update particle velocity and position
Continue simulation loop
No
Continue moving particle
The particle moves, checks for collisions, responds by updating velocity and position, then continues moving.
Execution Sample
Unity
void OnParticleCollision(GameObject other) {
    Vector3 normal = (transform.position - other.transform.position).normalized;
    velocity = Vector3.Reflect(velocity, normal);
}
This code detects collision and reflects the particle's velocity based on the collision normal.
Execution Table
StepParticle PositionOther Object PositionCollision Detected?Collision NormalVelocity BeforeVelocity AfterAction
1(0,0,0)(1,0,0)No-(1,0,0)(1,0,0)Particle moves forward
2(0.5,0,0)(1,0,0)No-(1,0,0)(1,0,0)Particle moves forward
3(1,0,0)(1,0,0)Yes(-1,0,0)(1,0,0)(-1,0,0)Reflect velocity on collision
4(0.9,0,0)(1,0,0)No-(-1,0,0)(-1,0,0)Particle moves backward
Exit--No---No more collisions, simulation continues
💡 Particle no longer collides, simulation continues with updated velocity.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4Final
Particle Position(0,0,0)(0.5,0,0)(1,0,0)(1,0,0)(0.9,0,0)(0.9,0,0)
Velocity(1,0,0)(1,0,0)(1,0,0)(-1,0,0)(-1,0,0)(-1,0,0)
Collision DetectedNoNoYesNoNoNo
Key Moments - 3 Insights
Why does the velocity change direction after collision?
Because the velocity is reflected using the collision normal vector, as shown in step 3 of the execution_table where velocity changes from (1,0,0) to (-1,0,0).
Why is there no collision detected at step 2 even though the particle is close to the other object?
Collision is detected only when positions overlap or intersect exactly, which happens at step 3. Step 2 position (0.5,0,0) is not colliding yet.
What happens if we don't update the velocity after collision?
The particle would continue moving in the same direction and pass through the object, ignoring the collision, unlike step 3 where velocity is updated to reflect the collision.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the velocity after step 3?
A(1,0,0)
B(-1,0,0)
C(0,1,0)
D(0,0,1)
💡 Hint
Check the 'Velocity After' column at step 3 in the execution_table.
At which step does the collision get detected?
AStep 1
BStep 2
CStep 3
DStep 4
💡 Hint
Look at the 'Collision Detected?' column in the execution_table.
If the particle velocity was not reflected on collision, what would happen at step 4?
AParticle would continue moving forward
BParticle would stop moving
CParticle would move backward
DParticle would teleport
💡 Hint
Refer to the 'Velocity After' and 'Action' columns in the execution_table for step 3 and 4.
Concept Snapshot
Particle collision in Unity:
- Detect collision using OnParticleCollision.
- Calculate collision normal vector.
- Reflect velocity using Vector3.Reflect.
- Update particle velocity and position.
- Continue simulation with new velocity.
Full Transcript
In Unity, particle collision happens when a particle moves and hits another object. The system checks if the particle's position overlaps with another object's position. When a collision is detected, the particle's velocity is reflected based on the collision normal vector, which changes its direction. This reflection is done using Vector3.Reflect. After updating velocity, the particle continues moving with the new velocity. The execution table shows step-by-step positions, collision checks, and velocity changes. Key moments clarify why velocity changes and when collisions are detected. The visual quiz tests understanding of velocity changes and collision detection steps.