- Home /
Detecting Collision from top side of 2d box collider
Hello i would like to know how to detect the collision side (specifically the top) to execute a certain thing when i do so, example when mario jumps ontop of mushroom it kills it instead of the side killing it
heres my code that i put on the AI that i want to detect if it collides
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Basic_AI : MonoBehaviour {
 
     public float AiSpeed;
 
     private void OnCollisionEnter2D(Collision2D collision)
     {
         if(collision.gameObject.tag == "Wall")
         {
             AiSpeed *= -1f;
         }
     }
 
     void Start() {
     }
     
     void Update () {
         BasicAI();
     }
 
     public void BasicAI()
     {
         transform.Translate(-AiSpeed, 0, 0);
     }
     public void AI_Flip()
     {
         Vector2 localScale = gameObject.transform.localScale;
         localScale.x *= -1;
         transform.localScale = localScale;
     }
 }
 
               Comment
              
 
               
              Your answer
 
 
             Follow this Question
Related Questions
I Can't Jump, And If I Remove if(isGrounded) I Can Do More Then 10 Jumps IN The Air 1 Answer
Ground Detection Lagging - 2D 2 Answers
2D Jump AI Help 0 Answers
My player wont jump (2d game) 1 Answer
Problem with Jump 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                