UNITY | PROJECT | SPACE SHOOTER 2D | 7. Collision Detection

2
Creating Tags
  • Create the tags for each GameObject
3
Tagging
  • Tagging each GameObject with its own Tag

 

4
Adding Collider & RigidBody2D to “Player”
5
Adding Collider & RigidBody2D to “Enemy”
6
Adding Collider & RigidBody2D to “PlayerBullet”
7
Adding Collider & RigidBody2D to “EnemyBullet”
  • Add Collider & RigidBody2D to each GameObject
    • Set “Is Trigger” in Collider to make it as “Trigger Collider”
    • SetGravity Scale in RigidBody2D to make them not to be affected by Gravity
    • Set “Freeze Rotation” in RigidBody2D to make them not spin when collided
8
OnTriggerEnter2D() | “PlayerControl” Script
9
OnTriggerEnter2D() | “EnemyControl” Script
10
OnTriggerEnter2D() | “PlayerBullet” Script
11.1
OnTriggerEnter2D() | “EnemyBullet” Script
  • Add “OnTriggerEnter2D(Collider2D)” method to each GameObject to detect and activate “Destroy()”
  • To Sort each Collision, Use “Collider2D.tag”

 

11.2

11.3
Collision Detection Working Well

13

125-e1531723319199.png
“PlayExplosion()” | “PlayerControl” Script
14.1
“PlayExplosion()” | “EnemyControl” Script
  • To Destroy “Player” or “Enemy”
    • Create a Function, “PlayExplosion()”
      • Instantiate the Explosion(Don’t forget to use “this.”)
    • Write the Function inside “TriggerEnter2D()” to make the instantiation of Explosion happen when a collision is detected
14.2
Explosion Animation & Collision Detection

UNITY TUTORIAL | PHYSICS | 3D Physics | Colliders as Trigger

UNITY TUTORIAL

PHYSICS | 3D Physics | Colliders as Trigger

 

collider-as-trigger1.png
Trigger | BoxCollider | Is Trigger

 

trigger1
Is Trigger
322.png
Trigger | BoxCollider | CollisionDetection script
4
OnTriggerEnter() | OnTriggerStay() | OnTriggerExit()
5
Falling Object | RigidBody
trigger2
OnTriggerEnter() | OnTriggerStay() | OnTriggerExit()
6
Hovering​ Script
7
Collider.attachedRigidBody | AddForce() | ForceMode.Acceleration()
hovering1
Hovering Simple
hovering2
Hovering Force Changing
8
Freeze Position
hovering3
Hovering with FallingObject Frozen