예제 #1
0
    private void OnRedirectedCollision(ProjectileHit projectileHit)
    {
        if ((hitMask.value & 1 << projectileHit.hitObject.layer) != 0 && projectileHit.hitObject != owner && !_collisionComplete)
        {
            _collisionComplete = true;

            ProcessCollision(projectileHit);
        }
    }
예제 #2
0
파일: Entity.cs 프로젝트: cloera/ZombieGame
    public virtual void OnHit(ProjectileHit proj)
    {
        health         -= proj.damage;
        healthBar.value = health;

        if (health <= 0)
        {
            Dead();
        }
    }
예제 #3
0
    private void SpawnProjectile()
    {
        GameObject projectile = GameObject.Instantiate(arrowPrefab);

        projectile.transform.position = projectilePosition.transform.position;
        projectile.transform.rotation = projectilePosition.transform.rotation;

        ProjectileHit hit = projectile.GetComponent <ProjectileHit>();

        hit.Host = host;
        hit.SetBounces(host.Stats.ProjectileBounces);
    }
예제 #4
0
    private void OnBulletHit(ProjectileHit projectileHitInfo)
    {
        if (projectileHitInfo.hitObject)
        {
            DamageInfo damageInfo = new DamageInfo();
            damageInfo.originPoint = projectileHitInfo.originPoint;
            damageInfo.impactPoint = projectileHitInfo.hitPoint;
            damageInfo.normal      = projectileHitInfo.normal;
            damageInfo.damageDone  = pointBlankDamage;

            projectileHitInfo.hitObject.SendMessage(GameMessages.TAKE_DAMAGE, damageInfo, SendMessageOptions.DontRequireReceiver);
        }
    }
예제 #5
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        if (tempIFrames == 0)
        {
            if (collision.gameObject.tag == "Projectile")
            {
                ProjectileHit tempProjectile = collision.gameObject.GetComponent <ProjectileHit>();

                ChangeHealth(-tempProjectile.damage);

                tempIFrames = tempProjectile.iFrames;
            }
        }
    }
예제 #6
0
    private void OnTriggerEnter(Collider other)
    {
        if ((hitMask.value & 1 << other.gameObject.layer) != 0 && other.gameObject != owner && !_collisionComplete)
        {
            _collisionComplete = true;

            ProjectileHit projectileHit = new ProjectileHit();
            projectileHit.originObject   = owner;
            projectileHit.originPoint    = originPoint;
            projectileHit.hitObject      = other.gameObject;
            projectileHit.hitObjectLayer = other.gameObject.layer;

            ProcessTriggerHit(ref projectileHit);
            ProcessCollision(projectileHit);
        }
    }
예제 #7
0
    private void OnCollisionEnter(Collision other)
    {
        if ((hitMask.value & 1 << other.gameObject.layer) != 0 && other.gameObject != owner && !_collisionComplete)
        {
            _collisionComplete = true;

            ProjectileHit projectileHit = new ProjectileHit();
            projectileHit.originObject   = owner;
            projectileHit.originPoint    = originPoint;
            projectileHit.hitObject      = other.gameObject;
            projectileHit.hitObjectLayer = other.gameObject.layer;
            projectileHit.normal         = other.contacts[0].normal;
            projectileHit.hitPoint       = other.contacts[0].point;

            ProcessCollision(projectileHit);
        }
    }
예제 #8
0
    private void Update()
    {
        Vector3 newPos = transform.position + Velocity * Time.deltaTime;

        Velocity += Physics.gravity * Time.deltaTime;

        if (Physics.Linecast(transform.position, newPos, out RaycastHit hit, CollisionMask))
        {
            PoolObject.Despawn(PoolObject);
            if (HitEffect != null)
            {
                var eff = PoolObject.Spawn(HitEffect);
                eff.transform.position = hit.point + hit.normal * 0.01f;
                eff.transform.forward  = -hit.normal;
                eff.transform.parent   = hit.collider.transform;
            }
            if (HitParticles != null)
            {
                var eff = PoolObject.Spawn(HitParticles);
                eff.transform.position = hit.point + hit.normal * 0.01f;
                eff.transform.forward  = -hit.normal;
            }

            var phit = new ProjectileHit()
            {
                WorldPoint       = hit.point,
                WorldNormal      = hit.normal,
                Collider         = hit.collider,
                IncomingVelocity = Velocity,
                HealthChange     = -Damage
            };

            LastHit = hit.point;

            hit.transform.SendMessageUpwards("UponProjectileHit", phit, SendMessageOptions.DontRequireReceiver);

            if (hit.collider.attachedRigidbody != null)
            {
                hit.collider.attachedRigidbody.AddForceAtPosition(Velocity.normalized * HitImpulse, hit.point, ForceMode.Impulse);
            }
        }
예제 #9
0
    void CheckCollisions(Collider2D collision)
    {
        if (tempIFrames == 0)
        {
            if (collision.gameObject.tag == "Enemy")
            {
                Enemy tempEnemy = collision.GetComponent <Enemy>();

                ChangeHealth(-tempEnemy.damage);

                tempIFrames = iFrames;
            }
            if (collision.gameObject.tag == "EnemyProjectile")
            {
                ProjectileHit tempProjectile = collision.GetComponent <ProjectileHit>();

                ChangeHealth(-tempProjectile.damage);

                tempIFrames = tempProjectile.iFrames;
            }
        }
    }
예제 #10
0
    public void UponProjectileHit(ProjectileHit hit)
    {
        if (IsDead && !CanChangeHealthWhenDead)
        {
            return;
        }

        int old = HP;

        HP += hit.HealthChange;
        if (HP > MaxHP)
        {
            HP = MaxHP;
        }
        if (HP < 0)
        {
            HP = 0;
        }

        if (old != HP)
        {
            UponHealthChange?.Invoke(this, HP - old, hit);
        }
    }
예제 #11
0
    void OnCollisionEnter(Collision collision)
    {
        ContactPoint contact = collision.contacts[0];

        if (GameObjectPoolManager.Instance.ProjectileHitDict.ContainsKey(ProjectileInfo.ProjectileType))
        {
            ProjectileHit hit = GameObjectPoolManager.Instance.ProjectileHitDict[ProjectileInfo.ProjectileType].AllocateGameObject <ProjectileHit>(ProjectileManager.Instance.transform);
            hit.transform.position = contact.point + contact.normal * hitOffset;
            hit.transform.rotation = Quaternion.FromToRotation(Vector3.up, contact.normal);
            if (UseFirePointRotation)
            {
                hit.transform.rotation = gameObject.transform.rotation * Quaternion.Euler(0, 180f, 0);
            }
            else if (rotationOffset != Vector3.zero)
            {
                hit.transform.rotation = Quaternion.Euler(rotationOffset);
            }
            else
            {
                hit.transform.LookAt(contact.point + contact.normal);
            }

            hit.ParticleSystem.Play(true);
            hit.PoolRecycle(hit.ParticleSystem.main.duration);
        }

        foreach (GameObject detachedPrefab in Detached)
        {
            if (detachedPrefab != null)
            {
                detachedPrefab.transform.parent = null;
            }
        }

        PoolRecycle();
    }
예제 #12
0
 public void Shoot(Vector3 facing, float spe, float dam, ProjectileHit hit)
 {
     hitType  = hit;
     velocity = facing * spe;
     damage   = dam;
 }
예제 #13
0
 private void ProcessCollision(ProjectileHit projectileHit)
 {
     ProcessBulletHit(projectileHit);
 }
예제 #14
0
 private void ProcessBulletHit(ProjectileHit projectileHit)
 {
     SendMessage(GameMessages.BULLET_HIT, projectileHit, SendMessageOptions.DontRequireReceiver);
 }
예제 #15
0
 private void ProcessTriggerHit(ref ProjectileHit projectileHit)
 {
     projectileHit.hitPoint = projectileHit.hitObject.collider.ClosestPointOnBounds(transform.position);
     projectileHit.hitObject.SendMessage(GameMessages.PROJECTILE_TRIGGER_HIT, projectileHit, SendMessageOptions.DontRequireReceiver);
 }
예제 #16
0
파일: Moose.cs 프로젝트: cloera/ZombieGame
 public override void OnHit(ProjectileHit proj)
 {
     base.OnHit(proj);
     CanadianFury();
 }
예제 #17
0
 public void Add(ProjectileHit hit) => m_ProjectileHit.Add(hit);
예제 #18
0
 public void SetCallbackObject(ProjectileHit ph)
 {
     callback = ph;
 }
예제 #19
0
 private void UponProjectileHit(ProjectileHit hit)
 {
     PoolObject.Despawn(this.PoolObject);
     Debug.Log("Nice shot!");
 }