UNITY | PROJECT | RPG Tutorial |14. Enemy AI

2
“SpiderAI” Script
  • create a variable for Player
  • in Update() method,
    • make Spider keep looking at Player by using transform.Lookat()
3
Adding Script
4
“SpiderAI”
  • create variables for
    • Player
    • distance obtained by RayCasting
    • distance where Enemy starts to move towards Player
    • Spider itself
    • speed of Spider
    • attack trigger to indicate when spider starts to attack
    • for RayCasting
  • in Update() method,
    • put the information from RayCasting to the RayCastingHit variable
    • put the distance from RayCasting into the variable for distance
    • if Player is within the minimum range of Spider,
      • set the speed of Spider
      • if attackTrigger is 0,
        • make Spider move with the animation, “walk”, toward Player by setting its tranform
    • if Player has left from the range of Spider,
      • set the speed of Spider into 0
      • make Spider idlen with the animation, “idle”
5-1
AI Working : Walking
5
Adding Script
6
“SpiderAI” Script
  • in Update() method,
    • add another if statement,
      • if attackTrigger is 1
        • set the speed of Spider into 0
        • make spider attack with animation, “attack”
  • in OntriggerEnter() method,
    • when spider touches somthing(Player), set attackTrigger into 1
  • in OntriggerExit() method,
    • when Player has escaped Spider, set attackTrigger into 0 to make it stop attack
7-2
AI Working : Attacking
7
Adding Collider
  • add Mesh Collider to Player
    • Convex, and is Trigger

UNITY TUTORIAL | PROJECT | SPACE SHOOTER |9. Creating Hazards

UNITY TUTORIAL | PROJECT | SPACE SHOOTER |9. Creating Hazards

2
Adding Asteroid as Hazard

 

3
Adding “RigidBody” and “Capsule Collider”

 

4
adding a script to give Tumbling
5
setting tumbling speed with a public variable
6
RigidBody.AngularVelocity | Random.insideUnitSphere
ezgif.com-video-to-gif
tumbling Asteroid but with Angular Drag
7
setting Angular Drag to 0
ezgif.com-video-to-gif-2
Asteroid tumbling without Angular Drag
8
adding a script to make destruction
9
OntriggerEnter to detect any collision | Destroy()
  • Destroy(other) – only removing the collider
  • Destroy(other.gameObject) – removing only the gameObject with Collider “other”
ezgif.com-video-to-gif-3
Bug | something is triggering “Destroy()” function
10
Debug.Log (other.name)
ezgif.com-video-to-gif-4
Debugging 1 | finding the cause
11
Debugging 2 | finding the cause
12
Debugging 3 | Tagging “Boundary”
13
Debugging 4 | detecting any gameObject with a tag “Bounadry” | return
  • Return ends the execution of a function and hands the control back the function that called it (maybe Unity itself)
  •  Return ends OntriggerEnter Function and returns the control back to Unity’s Game Loop
  • As a result, if the object’s tag is “Boundary”, we will never reach or execute “Destroy” function
ezgif.com-video-to-gif-5
Debugging 6 | Solved
ezgif.com-video-to-gif-6
Asteroid destroyed by Laser

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