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 | RigidBodies

UNITY TUTORIAL

PHYSICS | 3D Physics | RigidBodies

2.png
GameObject without RigidBody
3
GameObject without RigidBody
4
GameObject with RigidBody
ezgif.com-video-to-gif.gif
GameObject Falling under Gravity because of RigidBody
5
Project Setting | Physics
6
Physics Manager | Direction of Gravity
7
Changing the Direction of Gravity
ezgif.com-video-to-gif
GameObject Falling under Gravity in a different direction
9
Use Gravity | Is Kinematic
10
Board – Gravity On
11
Ball – Gravity On

1.2 gravity.gif

12
Board – Gravity
13
Ball – Gravity On

2. 1 gravity

14
Board Kinematic On
15
Ball – Gravity On

3. kinematic

16

17
To move Kinematic GameObject
ezgif.com-video-to-gif
Kinematic GameObject

the object still interacts with the others but remains a rigidbody,

so is constantly informing the physics engine of its location

and not forcing the physics engine to re-evaluate the entire scene.

18
Interpolate | ExtraPolate
19
Collision Detection
20
Constraints of Position and Rotation

 

ezgif.com-video-to-gif (1)
No Constraint

 

ezgif.com-video-to-gif
Rotation Constraint

 

UNITY TUTORIAL | PROJECT | Roll a Ball | 6. Collecting the Pick Up Object

Roll a Ball

Collecting the Pick Up Object

2
OnTriggerEnter() | CompareTag() | SetActive()
3
Add Tag
4
Add Tag
5
Add Tag
6
Apply Tag
7
Appy Tag
ezgif.com-video-to-gif.gif
SetActive not working
9
selcting
10
Unity’s Physics Engine | Static Collider | Dynamic Collider | Trigger | Trigger Collider
11
Collier | Trigger
12
Collier | Trigger

ezgif.com-video-to-gif (1)

13

14
RigidBody | Collider | Dynamic
15
Prefab | RigidBody | came to Dynamic
ezgif.com-video-to-gif (2)
RigidBody | Gravity
163.png
RigidBody | Gravity | Partial Solution
17
RigidBody | Gravity | Kinematic
ezgif.com-video-to-gif (3)
Gravity Overcome

 

18
Creating Variable as Reference
19
Creating UI Text

20

21
Chaing Position of UI
22
Configuring
23
NameSpace | UnityEngine.UI
24
Text.text | ToString
25
Custom Method to make the script shorter
26
Private Variable

 

ezgif.com-video-to-gif (1).gif
Text UI

 

27
Creating Win Text
28
changing​ the location of UI Text
29
Using Custom Method
30
Custom Variable
31
Private Variable
ezgif.com-video-to-gif (2)
UI Text

WEEK3 |Unity 2D Physics | Moving GameObject

2
GameObject | Unity Component | RigidBody2D
5
Physics 2D | Gravity
6
Project Settings | Physics 2D
8
Physics2D
10
Physics2D Setting | Gravity
9
RigdBody2D | GetComponent | RigidBody2D.AddForce

GetComponent

  • we can get other components that are attached to the same Game Object this script is attached to by calling “GetComponent” and we put that component into a variable

RigidBody2D.AddForce

  • public void AddForce(Vector2 force, ForceMode2D mode = ForceMode2D.Force);
  • ForceMode2D
    • ForceMode2D.Force – Add a force to the Rigidbody2D, using its mass.
    • ForceMode2D.Impulse – Add an instant force impulse to the rigidbody2D, using its mass.
11
Script Attached
12
GameObject Moving