ok here is my code for X movement…I’m making a sidescroller…I know the collision is taking place because I have an on collision event that stuns the player…but he just decides to ignore the collider of the bandit and thin walls…however I can’t make the collider on the bandit any bigger because he is only so big…here is my codes
This one handles x movement and is located in the Update() function
float wx = Input.GetAxis("Horizontal") * Time.deltaTime * curspeed;
if(isstuned == 0)
{
transform.Translate(wx, 0, 0);
}
this is the one that handles collisions this is taking place…but for some reason he is not getting knocked back or stopped…(I don’t think its the knockback code going the wrong way because it was ignoring collisions before I put this in)
IEnumerator OnCollisionEnter(Collision collision)
{
//with bandit
if (Time.time>nextDmg && collision.gameObject.tag == "Bandit")
{
nextDmg = Time.time + noDmg;
//if bandit is to the right
if (Physics.Raycast(transform.position,Vector3.right,10))
{
//take controls away from the player
isstuned -= 1;
//knock player to the left
rigidbody.velocity = -transform.right * knockback;
//minus 10 hp, and then print to console for debugging
hp -= BanditDmg;
print("-10 hp struck by bandit from the right"); //debug
yield return new WaitForSeconds(1);
//give controls back to the player
isstuned += 1;
}
//if bandit is to the left
if (Physics.Raycast(transform.position,Vector3.left,10))
{
//take controls away from the player
isstuned -= 1;
//knock player to the right
rigidbody.velocity = transform.right * knockback;
//minus 10 hp, and then print to console for debugging
hp -= BanditDmg;
print ("-10 hp struck by bandit from the left"); //debug
yield return new WaitForSeconds(1);
//give controls back to the player
isstuned += 1;
}
}
}