i have a script on 2 players but when they touch eachother aswell as touch the ground and then stop touching each other but continue to touch the ground they cant jump. can someone help me
this is the script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Tom_Movement : MonoBehaviour
{
public float moveSpeed = 5f;
public float jumpForce = 5f;
public GameObject Tim;
bool isGrounded;
private void Update()
{
if (Input.GetKey(KeyCode.RightArrow))
{
gameObject.GetComponent<Rigidbody2D>().AddForce(new Vector2(moveSpeed, 0f));
}
if (Input.GetKey(KeyCode.LeftArrow))
{
gameObject.GetComponent<Rigidbody2D>().AddForce(new Vector2(-moveSpeed, 0f));
}
if (isGrounded)
{
if (Input.GetKeyDown(KeyCode.UpArrow))
{
gameObject.GetComponent<Rigidbody2D>().AddForce(new Vector2(0f, jumpForce), ForceMode2D.Impulse);
}
}
}
private void OnCollisionEnter2D(Collision2D other)
{
if (other.collider.tag == "Ground" || other.collider.tag == "Player")
{
isGrounded = true;
}else if (other.collider.tag == "Ground" && other.collider.tag != "Player")
{
isGrounded = true;
}else if (other.collider.tag != "Ground" && other.collider.tag == "Player")
{
isGrounded = true;
}else if (other.collider.tag == "Ground" && other.collider.tag == "Player")
{
isGrounded = true;
}
}
private void OnCollisionExit2D(Collision2D other)
{
isGrounded = false;
}
}