Showing posts with label Unity. Show all posts
Showing posts with label Unity. Show all posts

26/09/2021

[Unity] Fury Farm

A sample 3D shooter game made with Unity.

Get the code from the repo or play online.

The animals have gone mad, defend your farm from their rage.

Controls:

AD - move left/right

SPACE - shoot

R - restart level

Q - quit

Interesting notes:

  • FindObjectOfType<OBJECT_NAME>(); get an object in a script without binding it in input
  • "this" is actually gameObject within a script
  • InvokeRepeating("METHOD_NAME", START_DELAY, REPEAT_RATE); added to an Awake or Start method, will ensure the given method is called repeatedly according to configuration
  • Random.Range(MIN, MAX) gives a random float between MIN and MAX both inclusive
  • WebGL default screen size is 960x600, the game default aspect is "Free Aspect" (top left of Game tab), change in File->Build Settings->Player Settings the resolution for WebGL to match a different one and set the Game aspect to the same to test how would it look like on the user screen
  • Cooldown logic can be added by tracking a float variable and updating it with -Time.deltaTime every frame, then checking if its value is less than some threshold to allow the player to execute the action again

24/09/2021

[Unity] Fury Skies

A sample 3D plane flying project made with Unity.

Get the code from the repo or play online.

Much anticipated sequel to the exciting Fury Roads, it's time to elevate your rage to the skies.

Controls:

WS - pitch (up/down)

SPACE - turbo

X - invert pitch controls (down/up)

R - restart level

Q - quit

PrintScreen - take a screenshot of that beauty in action

Alt+F4 - close your browser and go take a walk with your mask on

CapsLock - bring that rage to the comments section

 

Interesting notes:

  • GameObject component inheritance seems to behave differently from OOP inheritance, not all parent Components are inherited by the children (but are accessible via GetComponentInParent)
  • Time.deltaTime can be used in transforms to equalize values between different systems running at different framerates
  • FixedUpdate should be used to update physics related stuff (eg movement)
  • 3D is weird: X axis = depth, Y axis = height, Z axis = width. So movement forward is on Z axis. Camera is not considered in the default transforms. I understand this is because Z axis is the direction the player is facing, making "forward" a Z change rather than X.
  • Instantiate(PREFAB_PARTICLE_OBJECT, transform.position, Quaternion.identity).Play(); will spawn the particle effects in the current object position. Invoke this before destroying whatever you collided with and get an explosion animation.
  • 3D particles are weird, provide a material, shape and color or you get pink cubes even if you change the startColor
  • Input.GetAxis("Vertical") gives the current player input on Y axis (even in 3D)
  • 3D is weird part2: right side view of an object in coordinates 0,0,0 is a camera with Y axis rotation -90 and X axis delta of +10

23/09/2021

[Unity] Fury Roads

A sample 3D car driving project made with Unity.

Get the code from the repo or play online.

How to play is in readme or in game menu. Hit the barrier, avoid the boulder, be fast, release the rage.

Interesting notes:

  • AudioSource.PlayOneShot: use this passing an AudioClip as input to play a sound file once when triggered
  • Input.GetKeyDown(KeyCode): use this to determine whether the user pressed a particular key and avoid multiple triggers if the key was pressed over multiple frames
  • GameObject.SetActive: parent can trigger child objects active/inactive with this, eg to swap models for same object on a certain event
  • LateUpdate is invoked after Update, so if you have a follow camera, update position there to avoid jerky movement
  • transform.Translate: move object (slide)
  • transform.Rotate: move object (rotate)
  • Vector3 has many static predefined vectors available eg: forward, up, one, zero
  • Can tag objects and then check whether interaction happened with an object type looking at its tag eg: collision.gameObject.CompareTag(TAG) will be true if this object collided with TAG object
  • Time.timeScale set to 0 stops game time, but can still read player inputs
  • SceneManager requires import (using) UnityEngine.SceneManagement