UNITY | PROJECT | 2D PlatFormer | 5. Collectables

2
Creating “Coin”
  • create Coin
    • add Circle Collider 2D
      • make it Trigger Collider by checking Is Trigger
    • add RigidBody2D
      • make it Static Collider

 

3
“PlayerControl” Script
  • in OnTriggerEnter2D() method,
    • if a collision with Coin happens
      • add score by 10
      • destroy the gameObject itself (=Coin)
    • OnTriggerEnter2D vs OnCollisionEnter2D
      • When there are TriggerColliders, use OnTriggerEnter2D
      • When there are normal Colliders, use OnCollisionEnter2D

 

3-1
Collecting Coin Working

 

4
ProjectSetting | Physics2Dsetting
  • Uncheck “Queries Start in Colliders”
    • I guess Query there means anything to detect in physics such as RayCast
    • with that option checked, RayCasting starts from the inside of collider attached to GameObjects
    • with that option unchecked, RayCasting Starts from the collider attached to GameObjects

 

5
“Enemy” Inspector
  • Tag as “Enemy”
  • Set the layer as “Default”

 

6
“PlayerControl” Script
  • create a function, PlayerRayCast(),
    • attach RayCast by using RayCastHit2D, and Physics2D.RayCast(vector2 origin, vector2 direction)
    • create an if statment,
      •  give Player jump by using GetComponent<RigidBody2D>.AddForce()

 

7
“PlayerControl” Script
  • Add PlayerRayCast() function in Update() method

 

7-1
Jumping on “Enemy”

 

8
Experiment | Layer : Ignore RayCast
  • put Enemy back in IgnoreRayCast Layer

 

8-1
RayCasting Not Working
  • with the option, “Queries Start in Colliders” unchecked, Enemy is moving correctly because RayCasting Starts from the exterior of Collider attacked to Enemy
  • with the fact that Enemy belongs to Ignore RayCast layer, the RayCasting feature is not working

 

9
“EnemyControl” Script
  • in Update() method,
    • with the Raycasting feature, Enemy detects other objects horizontally
    • in the horizon, if Enemy collides with Player, Destroy Player

 

9-1
Jumping on “Enemy”

 

10
“PlayerControl” Script
  • in PlayerRayCast(),
    • set if statements with the conditions,
      • if Player hit anything, and if it is Enemy, make Player jump on Enemy
      • if Player hit anything, and if it is not Enemy, set the flag for jump as true
10-1
“Player” can jump anywhere but “Enemy”

 

 

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 | PROJECT | SPACE SHOOTER |2. The Player Game Object

UNITY TUTORIAL | PROJECT | SPACE SHOOTER |2. The Player Game Object

2
Adding Player GameObject
3
Resetting the position of “Player” into (0, 0, 0)
4
Transform.Position set to (0, 0, 0)
56.png
RigidBody Added | Gravity Unactivated
6
Capsule Collider Added
ezgif.com-video-to-gif
Changing Collider Size
8
Changing the direction of Collider into Z-Axis for configuration
9
Changing the Radius and Height of Collider
10
Adding “Mesh Collider” | only one collider should be added
11
“Mesh Renderer” off to see “Mesh Collider”
13
Simplified “Mesh” added to “Mesh Collider”
14
“Particle” added as Child GameObject of  “Player”
ezgif.com-video-to-gif 복사본
“Particle” effect

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

 

UNITY TUTORIAL | PHYSICS | 3D Physics | Collider

Unity Tutorial

Physics | 3D Physics | Collider

2

321.png
Sphere Collider
4
Capsule Collider
520-e1527730067201.png
Box Collider
6
Collider for Complex Shapes
7
Collider Hierarchy
814.png
Collider Hierarchy
9
Collider Hierarchy
10
Mesh Collider
11
Complex Mesh
12
Complex Collider
13
Complex Mesh

146.png

15
Sphere Collider | RigidBody
16
Box Collider
17
Mesh Collider
ezgif.com-video-to-gif
Collision