im trying to make a flappy bird game where the game will quit i got that but i cant get the flappy bird script to work the player just falls can someone help me make it not fall thorugh the ground i have a colider rigid body PLS HELP!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FlappyBirdScript : MonoBehaviour
{
// Move speed for the player
public float moveSpeed = 5f;
// Upward force applied to the player when space bar is pressed
public float upwardForce = 5f;
// Gravity force applied to the player
public float gravity = 9.8f;
// Initial position of the player
Vector3 initialPosition;
// Rigidbody component of the player
Rigidbody rb;
// Initialization
void Start()
{
// Store the initial position of the player
initialPosition = transform.position;
// Get the rigidbody component of the player
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
// If the player has fallen below the ground, reset their position to the initial position
if (transform.position.y < initialPosition.y)
{
transform.position = initialPosition;
rb.velocity = Vector3.zero;
}
// Move the player to the right
transform.position += Vector3.right * moveSpeed * Time.deltaTime;
// Apply gravity to the player
transform.position += Vector3.down * gravity * Time.deltaTime;
// Check if the space bar was pressed
if (Input.GetKeyDown(KeyCode.Space))
{
// Apply upward force to the player
rb.velocity = Vector3.up * upwardForce;
}
}
} is the script btw