I added a Raycasthit2D for hit detection in my game but the line that comes from the player is way too long and when I hit an enemy it looks like my player is some sort of Jedi which is not what I want.
This is a picture of the distance of the Raycast. (Hotline Miami sprite is a place holder). Is there any way to change the Raycast distance?
This is the code:
//melee attack
int layerMask = 1<<9;
layerMask = ~layerMask;
pa.attack ();
RaycastHit2D ray = Physics2D.Raycast (new Vector2 (this.transform.position.x, this.transform.position.y), new Vector2 (transform.right.x, transform.right.y),1.5f, layerMask);
Debug.DrawRay (new Vector2 (this.transform.position.x, this.transform.position.y), new Vector2 (transform.right.x, transform.right.y), Color.green);
if (curWeapon == null && ray.collider.gameObject.tag == "Enemy") {
EnemyAttacked ea = ray.collider.gameObject.GetComponent<EnemyAttacked> ();
ea.knockDownEnemy ();
} else if (ray.collider != null) {
if (ray.collider.gameObject.tag == "Enemy") {
EnemyAttacked ea = ray.collider.gameObject.GetComponent<EnemyAttacked> ();
ea.killMelee ();
}
}
}