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 | Adding Physics Forces

2
GameObject with RigidBody | Mass | Drag
3
AddForce() | OnMouseDown() | UseGravity
4
AddForce | ForceMode
5
RigidBody | Mass & Drag changed
addingForce
AddForce() | OnMouseDown()
drag
AddForce() | OnMouseDown | Drag increased

UNITY TUTORIAL | PROJECT | Roll a Ball | 2. Moving the Player

Roll a Ball

Moving the Player

2
Adding RigidBody
3
Added RigidBody
5
Using RigidBody with Script
6
MovePlayer Script | RigidBody | FixedUpdate | Input.GetAxis | AddForce
7
Adding Script as Component
8
Adding Speed as Public Variable
9
Public Value in the Inspector
10
Chaing Value directly in the Inspector

ezgif.com-video-to-gif-2.gif

117.png
Chaing Value directly in the Inspector

ezgif.com-video-to-gif-3

12

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