Hi I have a sphere that has rigidbody and ground ( both has colliders ), When I press space it doesn’t work
I implemented this script:
public class PlayerScript : MonoBehaviour
{
/*
Assgined with Player
Feel free to edit or take this code in other assets :)
*/
float forceSpeed = 15.0f;
float jumpForce = 5.0f;
bool isTouchGround = true;
Rigidbody rb;
private void Start()
{
rb = this.GetComponent<Rigidbody>();
}
private void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
Vector3 move = new Vector3(moveHorizontal, 0.0f, 0.0f);
rb.AddForce(move * forceSpeed * 25.0f * Time.deltaTime);
}
private void Update()
{
if (isTouchGround)
{
if (Input.GetKeyDown(KeyCode.Space))
{
rb.AddForce(Vector3.up * jumpForce);
}
}
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Ground")
{
isTouchGround = true;
}
}
void OnTriggerExit(Collider other)
{
if (other.gameObject.tag == "Ground")
{
isTouchGround = false;
}
}
}