public bool Hit(Ray r, double tMin, double tMax, out HitRecord hr) { hr = default; if (!Boundary.Hit(r, -MathUtils.Infinity, MathUtils.Infinity, out var hr1)) { return(false); } if (!Boundary.Hit(r, hr1.T + 0.0001, MathUtils.Infinity, out var hr2)) { return(false); } if (hr1.T < tMin) { hr1.T = tMin; } if (hr2.T > tMax) { hr2.T = tMax; } if (hr1.T >= hr2.T) { return(false); } if (hr1.T < 0) { hr1.T = 0; } var rayLen = r.Dir.Length; var distInsideBoundary = (hr2.T - hr1.T) * rayLen; var hitDist = NegInvDensity * Math.Log(MathUtils.RandDouble()); if (hitDist > distInsideBoundary) { return(false); } var t = hr1.T + hitDist / rayLen; var p = r.At(t); hr = new HitRecord { Point = p, T = t, IsFrontFace = true, Material = PhaseFunction, Normal = new Vec3(1, 0, 0), U = 0, V = 0 }; return(true); }
private void ApplyHit(IHittable target) { if (_mode == DeReconstructorMode.Deconstructing) { target.Hit(_damagePerHit, 0); _storedMatter += _damagePerHit; } else if (_mode == DeReconstructorMode.Reconstructing) { target.Hit(-_damagePerHit, 0); _storedMatter -= _damagePerHit; } _storedMatter = Mathf.Clamp(_storedMatter, 0, _maxStoredMatter); }
public color ComputeRayColor(Ray ray, IHittable world, int recursiveDepth) { if (recursiveDepth <= 0) { return(color.Zero); } var hitRec = new HitRecord(); // use t_min=0.001 to fix the shadow acne if (world.Hit(ray, 0.001, float.PositiveInfinity, out hitRec)) { Ray scattered = new Ray(); color attenuation = color.Zero; if (hitRec.material.Scatter(ray, ref hitRec, out attenuation, out scattered)) { return(attenuation * ComputeRayColor(scattered, world, recursiveDepth - 1)); } return(color.Zero); } var unit_dir = ray.Direction.unit_vector(); var t = 0.5 * (unit_dir.Y() + 1.0); color end = new color(1.0, 1.0, 1.0); color start = new color(0.5, 0.7, 1.0); return((1.0 - t) * end + t * start); }
public bool Hit(Ray r, double tMin, double tMax, out HitRecord hr) { if (!Box.Hit(r, tMin, tMax)) { hr = default(HitRecord); return(false); } var hitLeft = Left.Hit(r, tMin, tMax, out var hrl); var hitRight = Right.Hit(r, tMin, hitLeft ? hrl.T : tMax, out var hrr); if (hitRight) { hr = hrr; if (hr.Material == null) { Console.WriteLine("Returning HRR with null material"); } return(true); } if (hitLeft) { hr = hrl; if (hr.Material == null) { Console.WriteLine("Returning HRL with null material"); } return(true); } hr = default(HitRecord); return(false); }
public bool Hit(Ray r, double tMin, double tMax, out HitRecord hr) { var origin = r.Origin; var dir = r.Dir; origin[0] = CosTheta * r.Origin[0] - SinTheta * r.Origin[2]; origin[2] = SinTheta * r.Origin[0] + CosTheta * r.Origin[2]; dir[0] = CosTheta * r.Dir[0] - SinTheta * r.Dir[2]; dir[2] = SinTheta * r.Dir[0] + CosTheta * r.Dir[2]; var rotatedRay = new Ray(origin, dir, r.Time); if (!Child.Hit(rotatedRay, tMin, tMax, out hr)) { return(false); } var p = hr.Point; var normal = hr.Normal; p[0] = CosTheta * hr.Point[0] + SinTheta * hr.Point[2]; p[2] = -SinTheta * hr.Point[0] + CosTheta * hr.Point[2]; normal[0] = CosTheta * hr.Normal[0] + SinTheta * hr.Normal[2]; normal[2] = -SinTheta * hr.Normal[0] + CosTheta * hr.Normal[2]; hr.Point = p; hr.SetFaceNormal(rotatedRay, normal); return(true); }
public void HitCurrentTarget() { if (hitTarget != null) { hitTarget.Hit(settings.damage); } }
public void OverKill() { IHittable testSubject = getHittable(); testSubject.Hit(int.MaxValue); Assert.IsTrue(testSubject.CurrentHP <= 0, "HP: " + testSubject.CurrentHP); Assert.IsFalse(testSubject.Alive, "Survived"); }
public void DeathAtZero() { IHittable testSubject = getHittable(); testSubject.Hit(testSubject.CurrentHP); Assert.AreEqual(testSubject.CurrentHP, 0, "HP: " + testSubject.CurrentHP); Assert.IsFalse(testSubject.Alive, "Survived"); }
protected void Damage(int value, Collider2D hit) { IHittable hitable = hit.gameObject.GetComponent <IHittable>(); if (hitable != null) { hitable.Hit(value, ownerTransform); } }
//public void SetTarget(Vector3 pos) //{ //} public void Fire() { Debug.Log("Tower gun fire", this); fireTimer = 0; if (currentTarget.Hit(damage)) { NextTarget(); } }
public Vector3 Color(IHittable world) { if (world.Hit(this, 0, double.PositiveInfinity, out var hit)) { return(0.5d * (hit.Normal + new Vector3(1, 1, 1))); } var direction = Direction.UnitVector; var t = 0.5d * (direction.Y + 1); return((1d - t) * new Vector3(1, 1, 1) + t * new Vector3(0.5d, 0.7d, 1)); }
public void Attack() { var collisions = GetCollisions(_attackParameters[_attackDirection]); foreach (Collider2D collider in collisions) { IHittable hittable = collider.gameObject.GetComponent <IHittable>(); if (hittable != null) { if (!HasWallBetween(collider.transform.position)) { hittable.Hit(_attackDamage, _player.transform); Debug.Log($"Hit {collider.gameObject}", collider.transform); } else if (hittable is Switch) { hittable.Hit(_attackDamage, _player.transform); } } } }
public static Vector RayColor(Ray ray, IHittable world) { var(isHit, rec) = world.Hit(ray, 0, double.MaxValue); if (isHit) { return(0.5 * (rec.Normal + new Color(1, 1, 1))); } var unitDirection = Vector.UnitVector(ray.Direction); var t = 0.5 * (unitDirection.Y + 1.0); return((1.0 - t) * new Color(1.0, 1.0, 1.0) + t * new Color(0.5, 0.7, 1.0)); }
private void OnTriggerEnter2D(Collider2D other) { IHittable hittable = other.GetComponent <IHittable>(); if (hittable != null) { hittable.Hit(_damage, this.transform); } _rigidbody.velocity = Vector2.zero; _animation.SmoothRewind(); }
private void OnTriggerEnter(Collider other) { if (isAttacking) { IHittable hittable = other.GetComponentInParent <IHittable>(); if (hittable != null) { particleSystemHit.Play(true); hittable.Hit(this); } } }
public bool Hit(Ray r, double tMin, double tMax, out HitRecord hr) { var movedRay = new Ray(r.Origin - Offset, r.Dir, r.Time); if (!Child.Hit(movedRay, tMin, tMax, out hr)) { return(false); } hr.Point += Offset; hr.SetFaceNormal(movedRay, hr.Normal); return(true); }
public IEnumerator DamagingBehavior(IHittable h) { do { // Local damage only if ((Component)h != null && ((Component)h).gameObject != null) { h.Hit(new HitArguments(((Component)h).gameObject, this.gameObject) .withDamage(damage) .withDamageType(type) .withSourcePosition(new Vector3(transform.position.x, transform.position.z))); yield return(new WaitForSeconds(rate)); } } while (h != null && toDamage.Contains(h)); }
private void Punch() { animator.SetTrigger("punch"); audioSource.PlayOneShot(punchSound); RaycastHit2D hitInfo = Physics2D.Linecast(startPunch.position, endPunch.position, 1 << LayerMask.NameToLayer("Player")); if (hitInfo.collider != null) { IHittable hittable = hitInfo.collider.gameObject.GetComponent <IHittable>(); if (hittable != null) { hittable.Hit(HitForceVector); } } }
public void Hitting() { Random r = new Random(); IHittable testSubject = getHittable(); int hp = testSubject.CurrentHP; while (hp > 1) { int hit = r.Next(hp - 1) + 1; testSubject.Hit(hit); Assert.IsTrue(testSubject.CurrentHP < hp, "hp >= Current HP; Old: " + hp + ", New: " + testSubject.CurrentHP + " Damage: " + hit); Assert.IsTrue(testSubject.CurrentHP > 0, "hp < 0; Old: " + hp + ", New: " + testSubject.CurrentHP + " Damage: " + hit); Assert.IsTrue(testSubject.Alive, "Death; Old: " + hp + ", New: " + testSubject.CurrentHP + " Damage: " + hit); hp = testSubject.CurrentHP; } }
private void OnCollisionEnter2D(Collision2D collision) { IHittable hittable = collision.collider.attachedRigidbody.gameObject.GetComponent <IHittable>(); if (hittable != null) { HitResultType resultType = hittable.Hit(gameObject); if (resultType == HitResultType.DESTROY) { HideBullet(); } else if (resultType == HitResultType.RICOCHET) { Ricochet(collision); } } }
public void HitColliders(Collider[] colliders, int dmg, float force) { foreach (Collider col in colliders) { // not ourself? if (col.gameObject != gameObject) { Debug.Log($"Found {col.name}!"); // detecting whether or not they can be hit IHittable hp = col.GetComponent <IHittable>(); if (null != hp && !hp.IsDead()) { // HIT! Vector3 displacement = transform.forward * force; hp.Hit(dmg, displacement); } } } }
private void OnTriggerEnter2D(Collider2D other) { if (other.CompareTag(tagToHit) && other.gameObject != character.gameObject) { IHittable victim = other.transform.root.GetComponent <IHittable>(); if (victim != null && projectileIndex > 0) { victim.Hit(character, projectileIndex, attackIndex); } if (shouldScreenshakeOnHit) { Screenshake(shakeAmp, shakeTime); } if (shouldStopOnHit) { OnDestroyGO(); } } }
private Vector3 RayColour(Ray ray, IHittable world, int depth) { HitRecord rec = new(); if (depth <= 0) { return(new Vector3(0, 0, 0)); } if (world.Hit(ray, 0.001f, float.PositiveInfinity, ref rec)) { var target = rec.point + rec.normal + RandomInUnitSphere(); return(0.5f * RayColour(new Ray(rec.point, target - rec.point), world, depth - 1)); } Vector3 unit_dir = Vector3.Normalize(ray.direction); var t = 0.5f * (unit_dir.Y + 1.0f); var vec_colour = (1.0f - t) * white + (t * blue); return(vec_colour); }
public Vec3 GetColor(IHittable world, int depth, Vec3 background) { if (depth <= 0) { return(Vec3.Zero); } Interlocked.Increment(ref RayCount); if (!world.Hit(this, 0.001, MathUtils.Infinity, out var hr)) { return(background); } var emitted = hr.Material.Emitted(hr.U, hr.V, hr.Point); if (!hr.Material.Scatter(this, hr, out var attenuation, out var scattered)) { return(emitted); } return(emitted + attenuation * scattered.GetColor(world, depth - 1, background)); }
public IEnumerator DamagingBehavior(IHittable h) { do { // Local damage only if ((Component)h != null && ((Component)h).gameObject != null) { //Test if health pack is there to give health and that the player isn't at full health if (active && ((Component)h).GetComponentInParent <PlayerStats>().health != ((Component)h).GetComponentInParent <PlayerStats>().healthMax) { //Hit target with negative damage h.Hit(new HitArguments(this.gameObject, ((Component)h).gameObject) .withDamage(-1 * Health) .withDamageType(type)); //Remove health pack CmdSetActivee(false); active = false; // do this so we don't keep grabbing healthpacks until server responds } yield return(new WaitForSeconds(0)); } } while (h != null && toDamage.Contains(h)); }
private static void HitTaker_Hit(On.HitTaker.orig_Hit orig, UnityEngine.GameObject targetGameObject, HitInstance damageInstance, int recursionDepth) { HitInfo info = Misc.ConvertHitInstance(damageInstance); if (targetGameObject != null) { Transform transform = targetGameObject.transform; for (int i = 0; i < recursionDepth; i++) { IHittable hittable = transform.GetComponent <IHittable>(); if (hittable != null) { hittable.Hit(info); } transform = transform.parent; if (transform == null) { break; } } } orig(targetGameObject, damageInstance, recursionDepth); }
void OnCollisionEnter2D(Collision2D coll) { IHittable hitted = coll.gameObject.GetComponent <IHittable>(); if (hitted != null && thrown) { hitted.Hit(size, gameObject); thrown = false; AkSoundEngine.PostEvent("Play_Hit", coll.gameObject); } else if ((wallLayer.value & 1 << coll.collider.gameObject.layer) != 0 && collTimer > 0.5f) { Debug.Log("collide"); changed = true; stickedCollider = coll.collider; stickedLastPosition = stickedCollider.transform.position; stickedLastRotation = stickedCollider.transform.rotation; rigid.gravityScale = 0; //StickToCollider(false); //Debug.Log("Sticked collider: " + coll.gameObject); thrown = false; collTimer = 0; } }
public void HitBlock(IHittable hittable) { hittable.Hit(_moveVector); }
public void Hit(float damage) { m_successor.Hit(damage); }
/// <summary> /// It's possible the tip of the projectile has already passed the object, resulting in a missed hit. /// The way to get around this is to basically spherecast along the entire displacement vector, which will /// allow us to determine if (even though we've passed the mesh) the projectile *would have* hit the mesh if /// it were slower (or the framerate was faster). /// </summary> void Update() { bool found = false; // How far did we move this frame? Vector3 displacement = projectileFront.position - lastBackPosition; // Find everything we've collided with...but use the closest mesh. RaycastHit[] hits = Physics.SphereCastAll(lastBackPosition, 1, displacement.normalized, displacement.magnitude, -1, QueryTriggerInteraction.Collide); RaycastHit closest = new RaycastHit { distance = Mathf.Infinity }; foreach (RaycastHit hit in hits) { IHittable hittable = hit.collider.gameObject.GetComponentInParent <IHittable>(); if (hittable != null && hittable.IsValidHit(hit, firedFrom) && hit.distance < closest.distance) { found = true; closest = hit; } } // We have a hit but we might be inside a collider.... if (found) { IHittable hittable = closest.collider.gameObject.GetComponentInParent <IHittable>(); if (closest.distance <= 0f) { closest.point = projectileBack.position; closest.normal = -transform.forward; /// its behind us } // Break up the projectile. if (explosion != null) { Instantiate(explosion, closest.point, Quaternion.identity); } // Show the mark if (bulletMark != null) { Instantiate(bulletMark, closest.point, Quaternion.identity); } if (hittable != null) { // Ask the hittable if this is a valid hit. if (hittable.IsValidHit(closest, firedFrom)) { hittable.Hit(transform, projectile.transform, closest, this); } } // Destroy the projectile. Destroy(projectile.gameObject); } lastBackPosition = projectileBack.position; }