So recently, my previous prototype has a Unity IO Error, and I couldn’t figure out how to fix it, so I just remade the entire prototype replicating everything, but for some reason my player character refuses to move after colliding with an enemy once despite me setting their lifespan to three hits. There are no errors in the console, this is the exact same script I wrote for the prototype, I messed around with the rigidbody, etc.
Here is the collision method:
private void OnCollisionEnter(Collision collision)
{
//The force in which the player will be affected by - when in contact
float force = 3000f;
if (collision.gameObject.CompareTag("Enemy"))
{
//Inform me the player was hit
Debug.Log("Enemy hit the player.");
//Call the Coroutine/IEnumerator that activate the slow-mo effect and the enemy hit bool
StartCoroutine(ActivateSlowMotion());
StartCoroutine(EnemyHitBool());
//Minus the player's health by 1
playerHp = playerHp - 1;
if (playerHp < 1)
{
gameOver = true;
Vector3 dir = collision.contacts[0].point - transform.position;
dir = -dir.normalized;
GetComponent<Rigidbody>().AddForce(dir * force);
speed = 0f;
}
}
}
I feel like it could be the force that pushes the player character into the opposite direction, but that is when the playerHp is less than 1, so I’m just a bit stumped.