Controls

wasd to move 

shoot with mouse left click or spacebar

Code

https://github.com/katpavan/asteroids

Learned/Notes

  • prefabs for bullet and asteroid
    • both dynamic Rigidbody2D because we want physics to act on them
  • bullets are kinematic since we don't want physics to act on them
    • if we did, then we'd make them dynamic
  • Instantiate 
    • to create bullets from the prefab
  • OnCollisionEnter2D
    • to detect collisions with game objects that have colliders
  • FixedUpdate
    • recommended to use when dealing with physics since it goes off on a set interval unlike Update which is dependent on a player's machine (framerate)
  • physics 
    • _rigidbody.AddForce
    • _rigidbody.AddTorque
    • _rigidbody.mass
  • this.gameObject.SetActive(false)
  • used FindObjectOfType 
    • instead of utilizing the Singleton pattern
  • Destroy(this.gameObject, maxLifetime);
    • to destroy asteroids and bullets
  • asteroid stuff
    • InvokeRepeating
      • to spawn asteroids
    • _spriteRenderer.sprite = sprites[Random.Range(0, sprites.Length)];        
      • randomize asteroid image
    •  this.transform.eulerAngles = new Vector3(0.0f, 0.0f, Random.value * 360.0f);
      • randomize rotation                 
    • this.transform.localScale = Vector3.one *  this.size; 
      • randomize scale
StatusOn hold
PlatformsHTML5
Authorpavankat
GenreShooter
Made withUnity

Leave a comment

Log in with itch.io to leave a comment.