Beispiel #1
0
    public virtual void CheckForValidHitscan(Vector3 muzzle, Vector3 weaponDir, LayerMask layerMask)
    {
        Ray        ray    = new Ray();
        RaycastHit rayHit = new RaycastHit();

        ray.origin    = muzzle;
        ray.direction = transform.forward;

        var didHit = Physics.Raycast(ray, out rayHit, Mathf.Infinity, layerMask);

        bulletTracer.SetPosition(0, muzzle);
        bulletTracer.SetPosition(1, rayHit.point);
        bulletTracer.enabled = true;

        if (!didHit)
        {
            return;
        }

        var      isPlayer = rayHit.collider.CompareTag("PlayerHitbox");
        var      isNPC    = rayHit.collider.CompareTag("NPCHitbox");
        ValidHit NewHit   = new ValidHit();

        //Can prob refactor if player / npc have common baseclass
        if (isPlayer || isNPC)
        {
            AbstractCharacter target;
            if (isNPC)
            {
                target = rayHit.collider.GetComponent <BossMonster>();
            }
            else
            {
                target = rayHit.collider.GetComponentInParent <PlayerHitbox>().player;
            }

            NewHit.OriginatingEntityType       = player.ENTITY_TYPE;
            NewHit.OriginatingEntityIdentifier = player.ID;
            NewHit.VictimEntityType            = target.ENTITY_TYPE;
            NewHit.VictimEntity = target;
            NewHit.DamageAmount = DamageAmount;
        }
        // if not player or npc then it hit terrain
        else
        {
            // if bullethole graphic create one at the impact point
            if (BulletHole != null)
            {
                GameObject bulletHole      = Instantiate(BulletHole, rayHit.point, Quaternion.FromToRotation(Vector3.up, rayHit.normal));
                var        particleSystems = bulletHole.GetComponentsInChildren <ParticleSystem>();
                Destroy(bulletHole, 3f);
            }
        }
        if (OnValidHitOccurred != null)
        {
            OnValidHitOccurred(NewHit);
        }
    }
Beispiel #2
0
    public void RegisterNewValidHit(AbstractCharacter originator, AbstractCharacter target, int DamageAmount)
    {
        ValidHit NewHit = new ValidHit();

        NewHit.OriginatingEntityType       = originator.ENTITY_TYPE;
        NewHit.OriginatingEntityIdentifier = originator.ID;
        NewHit.VictimEntityType            = target.ENTITY_TYPE;
        NewHit.VictimEntity = target;
        NewHit.DamageAmount = Mathf.RoundToInt(DamageAmount * originator.damageMultiplier);

        if (OnValidHitOccurred != null && NewHit != null)
        {
            OnValidHitOccurred(NewHit);
        }
    }
Beispiel #3
0
 public void AddValidHit(ValidHit NewHit)
 {
     HitsToBeProcessed.Add(NewHit);
 }