How to only allow collision only on bottom side of 2d box collider Not top!
How to only allow collision only on bottom side of 2d box collider Not top! I only want players sword to be able to react if it hits the bottom side of the enemies 2d box collider as you know when colliders are set when you touch top sides or bottom they trigger
--so I only want the bottom to collide etc with players sword. so lets say if player swings sword on top of enemy 2d box collider , then it will not register , I only want to react if hits bottom of collider
2d game c#
1 yes all 2d game and colliders
2 yes many enemys spawning
3 yes bottom of anywhere on the enemy (bottom)
1 enemy is spawned randomly and moves all over screen
2 so far yes 1 , 2d box collider on enemy and player sword has box collider on edge of sword.
3 no I may do that later but no, rite now no triggers anywhere
4 so far 1, 2d box collider on enemys
I have spawn scripts if needed but to keep things simple heres death script only
using UnityEngine;
using System.Collections;
public class fishdedd : $$anonymous$$onoBehaviour {
//Animation anim;
public bool isDead = false; //has the player collided with a wall?
Animator anim; //reference to the animator component
void Start()
{
anim = GetComponent<Animator> ();
}
void OnCollisionEnter2D(Collision2D other)
{
if (other.gameObject.tag == "Player")
{
//Animation.Play("fishded");
anim.Play("fishded");
anim.SetTrigger("Die");
//GetComponent<Animation>().Play ("fishded");
Destroy (gameObject, 1.3f);
isDead = true;
GetComponent<AudioSource> ().Play ();
}
}
}
Answer by MirkoSon · Oct 21, 2020 at 12:43 PM
You need to use the Platform Effector 2D as shown in this video: https://www.youtube.com/watch?v=M_kg7yjuhNg
Cheers.
Answer by OutOfRam · Nov 27, 2016 at 10:09 AM
you cant.
Unity's collision system works by detecting whether an abject intersects an area(the colliders area) not its sides. what you are going to need to do is have multiple colliders on multiple game objects. Have the collider you want to receve damage when hit on an empty gameobject with a damage script attached to it.