Search Unity

How would one go on making a "directional hitbox"

Discussion in 'Game Design' started by BDslick04, May 13, 2022.

  1. BDslick04

    BDslick04

    Joined:
    May 18, 2021
    Posts:
    6
    What I mean is in games like Yakuza and Bully, there are 2 types of hit reactions. One for a front hit and one from the back. Is it possible to replicate something like that in Unity?
     
  2. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,609
  3. Not_Sure

    Not_Sure

    Joined:
    Dec 13, 2011
    Posts:
    3,546
    Just have the thing hitting the player have a direction then compare it to the direction of the player.
     
  4. BIGTIMEMASTER

    BIGTIMEMASTER

    Joined:
    Jun 1, 2017
    Posts:
    5,181
  5. BDslick04

    BDslick04

    Joined:
    May 18, 2021
    Posts:
    6
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class AttackUniversal : MonoBehaviour
    {
    public LayerMask collisionLayer;
    public float radius = 1f;
    public float damage = 2f;

    public bool is_Player, is_Enemy;

    public GameObject hit_FX;

    void Update()
    {
    DetectCollision();
    }

    void DetectCollision() {

    Collider[] hit = Physics.OverlapSphere(transform.position, radius, collisionLayer);

    if(hit.Length > 0) {

    print("We Hit the " + hit[0].gameObject.name);

    gameObject.SetActive(false);
    }
    }
    }

    How would I apply the direction in this script? Where would I put it?
     
  6. GimmyDev

    GimmyDev

    Joined:
    Oct 9, 2021
    Posts:
    160
    I would use a dot product between the receiver and the input hit direction, using the local axis of the receiver.
     
  7. BDslick04

    BDslick04

    Joined:
    May 18, 2021
    Posts:
    6
    I looked at what dot is, and it definitely looks like what I need. Thanks!