,I wanna make my player fall but instead, he just feathers down and gravity doesn’t take effect. I have the use of gravity checked on my rigidbody, and I skimmed through my movement script and it doesn’t seem that anything was affecting it
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour
{
public float Speed;
private Rigidbody rb;
public bool isGrounded = true;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
float hmove = Input.GetAxis("Horizontal");
float vmove = Input.GetAxis("Vertical");
Vector3 Direction = new Vector3(hmove, 0, vmove);
Direction.Normalize();
rb.velocity = transform.TransformDirection(Direction * Speed);
if (Input.GetKeyDown(KeyCode.Space) && isGrounded == true)
{
isGrounded = false;
rb.AddForce(new Vector3(0, 5000, 0), ForceMode.Impulse);
}
}
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "Ground")
{
isGrounded = true;
}
}
}