예제 #1
0
        public void Tick()
        {
            // Ignore if range is infinite
            if (damage.impactRange > 0)
            {
                // TODO: Extend Vector3 to include SqrDistance
                m_distance += Vector3.Distance(m_prevPosition, owner.transform.position);

                if (m_distance >= damage.impactRange)
                {
                    damage.ApplyDamage(null, damage.impactRange, owner.transform.position, owner.transform.position - m_prevPosition);

                    // Destroy self
                    Object.Destroy(owner.gameObject);
                }

                m_prevPosition = owner.transform.position;
            }

            // Accelerate, if necessary
            if (acceleration > 0 && m_projectile.rigidbody.velocity.magnitude < maxSpeed)
            {
                m_projectile.rigidbody.velocity += owner.transform.forward * acceleration * Time.deltaTime;
            }

            if (target != null)
            {
                float step      = angularSpeed * Mathf.Deg2Rad * Time.deltaTime;
                var   direction = Vector3.RotateTowards(owner.transform.forward, target.transform.position, step, 0f);
                owner.transform.rotation = Quaternion.LookRotation(direction);
            }
        }
예제 #2
0
 protected virtual void Hit(bool hitResult, RaycastHit hit)
 {
     if (hitResult)
     {
         damage.ApplyDamage(hit.collider.gameObject, muzzleBone.position, hit.point, hit.normal);
     }
 }