Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Flappy bird game powerups.

Discussion in 'Getting Started' started by MarshallMedia, Jan 24, 2022.

  1. MarshallMedia

    MarshallMedia

    Joined:
    Aug 1, 2020
    Posts:
    11
    Hello, i am trying to learn how to create power up for a flappy bird clone i am working on. What i am trying to do is create a power up that allows the player to dash forward while maintaining their current Y position. The player "movement" is based on the stage itself moving so im not entirely sure where to start. Here is a copy of all the scripts im currently using in this project.

    --Player movement script--
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using TMPro;
    5. using UnityEngine.SceneManagement;
    6.  
    7. public class PlayerMovement : MonoBehaviour
    8. {
    9.     public Rigidbody2D rb;
    10.     public TextMeshProUGUI scoreText;
    11.     public float jumpAmount = 8f;
    12.  
    13.     private int score;
    14.  
    15.     // Update is called once per frame
    16.     void Update()
    17.     {
    18.         if (Input.GetKeyDown(KeyCode.Space))
    19.         {
    20.             rb.velocity = new Vector2(0, jumpAmount);
    21.         }
    22.      
    23.      
    24.     }
    25.  
    26.     private void OnTriggerExit2D(Collider2D collision)
    27.     {
    28.         if (collision.gameObject.CompareTag("ScoreTrigger"))
    29.         {
    30.             score++;
    31.             scoreText.text = score.ToString();
    32.         }
    33.     }
    34.  
    35.     private void OnCollisionEnter2D(Collision2D collision)
    36.     {
    37.         SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
    38.     }
    39. }


    --Obstacle Generator--
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class ObstacleGenerator : MonoBehaviour
    6. {
    7.  
    8.     public GameObject obstaclePrefab;
    9.     public int generationRate = 100;
    10.  
    11.     private int timer;
    12.  
    13.    
    14.  
    15.     // Update is called once per frame
    16.     void FixedUpdate()
    17.     {
    18.         timer++;
    19.         if(timer >= generationRate)
    20.         {
    21.             timer = 5;
    22.             GameObject newObstacle = Instantiate(obstaclePrefab, new Vector2(obstaclePrefab.transform.position.x, obstaclePrefab.transform.position.y + Random.Range(-2f, 2f)), obstaclePrefab.transform.rotation);
    23.             Destroy(newObstacle, 100f);
    24.  
    25.         }
    26.     }
    27. }
    --Obstacle Movement Manager--
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class ObstacleMovement : MonoBehaviour
    6. {
    7.     public float moveSpeed = 5f;
    8.  
    9.     // Update is called once per frame
    10.     void FixedUpdate()
    11.     {
    12.         transform.position = Vector2.Lerp(transform.position, new Vector2(transform.position.x - moveSpeed, transform.position.y), 0.1f);
    13.     }
    14.  
    15.     void Update()
    16.     {
    17.      
    18.     }
    19.    
    20. }

    As i said, i am trying to figure out how to make a power up that gives the effect of the player dashing forward while keeping their current altitude. I would also like the power up to have 3 uses before going away and for it to have a short cooldown between each use. So as an example, DASH ...cooldown... DASH ...cooldown... DASH, -power up gone. That sort of thing. I have tried to work it out myself and had some luck however i ran into some issues. For one, at times the dash didnt seem to work at all. Another problem was that the game failed to recognize the player successfully clearing the gaps between the pillars when using the dash ability. Also, it seemed when using the dash ability it would only effect the pillars ahead of the player and not the ones they had already passed which looked really weird. Sorry i cant quite describe it more clearly, if anyone has some suggestions and/or some code they think will help i would really appreciate it.

    Thank you for your time!