public static void HandleCollisionEnter(Hittable collidingHittable, GameObject otherCollidingObject) { if (otherCollidingObject.gameObject.TryGetComponent <PlayerLife>(out _)) { return; } Airship collidingAirship = collidingHittable.gameObject.GetComponentInParent <Airship>(); Airship otherCollidingAirship = otherCollidingObject.gameObject.GetComponentInParent <Airship>(); if (collidingAirship && otherCollidingAirship && collidingAirship == otherCollidingAirship) { return; // Airship, don´t hit yourself } Vector3 relativeVelocity = Vector3.zero; int damage = 0; if (collidingAirship && otherCollidingAirship) { relativeVelocity = collidingAirship.Velocity - otherCollidingAirship.Velocity; damage = Mathf.FloorToInt(Vector3.Magnitude(relativeVelocity)); } else { //relativeVelocity = collidingAirship.Velocity; damage = collidingHittable.MaxHealth * 2; } collidingHittable.GetDamage(damage); }
protected void Attack(Hittable hittable) { attacking = true; StartCoroutine(AttackCouroutine(hittable)); StartCoroutine(AttackAnimationCouroutine()); Hit(); }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { sound.Shoot(); // Get middle of screen Vector3 point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0); Ray ray = _camera.ScreenPointToRay(point); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { // Debug.Log ("Hit " + hit.point); GameObject hitObject = hit.transform.gameObject; // You couldn't hit 2 things at once, could you? Hittable target = hitObject.GetComponent <Hittable> (); if (target != null) { Debug.Log("inlficting damage!!!"); target.ReactToHit(damage); } else { // StartCoroutine (SphereIndicator (hit.point)); } } } }
private void OnTriggerEnter(Collider other) { if (other.attachedRigidbody == null) { return; } Hittable hittable = other.attachedRigidbody.GetComponent <Hittable>(); if (hittable != null) { if (hittable.team == team) { return; } hittable.Hit(damagePerShot); Destroy(gameObject); return; } Bullet otherBullet = other.attachedRigidbody.GetComponent <Bullet>(); if (otherBullet != null && otherBullet.team != team) { UpdateBullet(otherBullet); otherBullet.UpdateBullet(this); } }
static IObservable <ChangeSelection> ChangeSelectionOnClick(Hittable ctrl, IObservable <ObjectIdentifier> selection, PluginContext ctx) { return(Observable.Merge( ctrl.Moved .WithLatestFromBuffered(selection, (pos, currentSelection) => new ChangeSelection { IsPreview = true, Id = HitTest(pos, currentSelection, ctx), }), ctrl.Pressed .WithLatestFromBuffered(selection, (pos, currentSelection) => { var newSelection = HitTest(pos, currentSelection, ctx); var newPreviewSelection = HitTest(pos, newSelection, ctx); return new { newSelection, newPreviewSelection }; }) .SelectMany(t => new[] { new ChangeSelection { IsPreview = true, Id = t.newPreviewSelection, }, new ChangeSelection { IsPreview = false, Id = t.newSelection, }, }))); }
private static Vector3 rayColor(Ray r, Hittable world, int depth) { HitRecord record = new HitRecord(); // Stop gathering light if the ray bounce limit is exceeded // Prevents stack overflow due to recursive function in the next section if (depth <= 0) { return(new Vector3(0, 0, 0)); } // 0.001 minimum prevents shadow acne if (world.Hit(r, 0.001, Double.MaxValue, record)) { Ray scattered = new Ray(); Vector3 attenuation = new Vector3(); if (record.Material.Scatter(r, record, attenuation, scattered, rand)) { return(attenuation * rayColor(scattered, world, depth - 1)); } return(new Vector3(0, 0, 0)); // Return black } // Render a blue-to-white gradient background if no hit Vector3 unitDirection = r.Direction.Normalize(); double t = 0.5 * (unitDirection.Y + 1); Vector3 white = (1.0 - t) * new Vector3(1.0, 1.0, 1.0); Vector3 blue = t * new Vector3(0.5, 0.7, 1.0); return(white + blue); }
private Vec3 RayColor(Ray r, Hittable world, int depth) { HitRecord rec = new HitRecord(); // If we've exceeded the ray bounce limit, no more light is gathered if (depth <= 0) { return(new Vec3()); } if (world.Hit(r, 0.001, Double.PositiveInfinity, ref rec)) { Ray scattered = new Ray(); Vec3 attenuation = new Vec3(); if (rec.Material.Scatter(r, rec, ref attenuation, ref scattered)) { return(attenuation * RayColor(scattered, world, depth - 1)); } return(new Vec3()); } Vec3 unitDirection = Vec3.UnitVector(r.Direction); double t = 0.5 * (unitDirection.Y + 1.0); return((1.0 - t) * new Vec3(1.0, 1.0, 1.0) + t * new Vec3(0.5, 0.7, 1.0)); }
public IEnumerator DamagingBehavior(Hittable h) { do { h.Hit(damage, type); yield return(new WaitForSeconds(rate)); } while (h != null && toDamage.Contains(h) && h.gameObject != null); }
private void OnTriggerExit2D(Collider2D collision) { Hittable h = collision.gameObject.GetComponent <Hittable>(); if (h != null) { hittable.Remove(h); } }
public BulletMaterialsInfo(Material material, Renderer renderer, float existanceTime, int poolId, Vector3 hitDataPos, Hittable hittable) { this.material = material; this.renderer = renderer; this.existenceTime = existanceTime; this.poolId = poolId; this.hitPos = hitDataPos; this.hittable = hittable; }
void OnTriggerEnter(Collider other) { Hittable hitObject = other.GetComponent <Hittable>(); if (hitObject != null) { hitObject.ReactToHit(damage); } }
public Material GetRandomBulletMaterial(Renderer renderer, Hittable hittable, Vector3 collisionPoint) { handyIndex = UnityEngine.Random.Range(0, materials.Length); var randomMat = materials[handyIndex]; var newMaterial = bulletHitPools[randomMat].GetObject(); existingMaterials.Add(new BulletMaterialsInfo(newMaterial, renderer, singleHitExistence, handyIndex, collisionPoint, hittable)); return(newMaterial); }
private void OnCollisionEnter(Collision collision) { Hittable hit = collision.gameObject.GetComponent <Hittable>(); if (hit != null) { hit.TakeDamage(this.damage); } Destroy(gameObject); }
public Translation(Vec3 offset, Hittable hittable) { if (hittable.Kind != PTObjectKind.Hittable) { throw new ArgumentException("Invalid PTObjectKind: not a Hittable.", nameof(hittable)); } Offset = offset; Hittable = hittable; }
override public void OnInspectorGUI() { Hittable h = (Hittable)target; if (GUILayout.Button("Simulate hit")) { h.Hit(); } DrawDefaultInspector(); }
// Use this for initialization void Start() { parentHit = GetComponentInParent <Hittable> (); parentRend = GetComponentInParent <SpriteRenderer> (); myRend = GetComponent <SpriteRenderer> (); length = transform.localScale.x; offsety = parentRend.sprite.bounds.size.x + 4 * myRend.sprite.bounds.size.y; offsetLength = myRend.sprite.bounds.size.x; myRend.enabled = false; }
public void SpawnWave(Wave w) { foreach (Hittable e in w.enemies) { Hittable newEnemy = Instantiate(e.gameObject, e.transform.localPosition, e.transform.localRotation).GetComponent <Hittable>(); newEnemy.transform.position += new Vector3(15, 0, 0); newEnemy.enabled = true; newEnemy.gameObject.SetActive(true); } }
private void OnTriggerEnter(Collider other) { Hittable hittable = other.gameObject.GetComponent <Hittable>(); //try getting Building component if (hittable != null && !hittable.IsEnemy) //if the collider has a building component attached { hittable.GetDamage(damage); //Do damage to the building DestroyBomb(); } }
private void OnTriggerExit2D(Collider2D other) { Hittable hittable = other.GetComponent <Hittable>(); if (null != hittable) { Debug.Log("Removed: " + hittable.name); _hittablesInRange.Remove(hittable); } }
private void Awake() { hittable = GetComponent <Hittable>(); TimeManager.Instance.OnTimeFactorChanged += onTimeFactorChanged; if (hittable != null) { hittable.OnHitterActivated += onHitterActivated; } }
public Rotation(float theta, Alignment axis, Hittable hittable) { if (axis != Alignment.X && axis != Alignment.Y && axis != Alignment.Z) { throw new ArgumentException("Invalid Alignment: must be X, Y, or Z.", nameof(axis)); } Theta = theta; Axis = axis; Hittable = hittable; }
protected virtual void OnRangeEnter(AttackRangeController attackRange, GameObject gameObject) { if (gameObject.transform == target) { targetReached = true; Hittable hittable = gameObject.GetComponent <Hittable>(); if (hittable != null) { Attack(hittable); } } }
void RemoveHittable(Collider2D other) { //Grabs the hitable component from the object you collided with Hittable hittable = other.GetComponent <Hittable>(); //Checks if its not null if (null != hittable) { //Removes the hittable from the list hittablesInRange.Remove(hittable); } }
private void OnCollisionEnter2D(Collision2D collision) { if (targets.Contains(collision.gameObject.tag)) { Hittable hittable = collision.gameObject.GetComponent <Hittable>(); if (hittable != null) { collision.gameObject.GetComponent <Hittable>().GetHit(); } Destroy(gameObject); } }
protected IEnumerator AttackCouroutine(Hittable hittable) { hittable.Hit(); Stop(); yield return(new WaitForSeconds(stats.fireRate.ValueFloat)); attacking = false; if (targetReached) { Attack(hittable); } }
private void OnCollisionEnter2D(Collision2D collision) { if (!collision.gameObject.CompareTag("Player")) { Hittable hittable = collision.gameObject.GetComponent <Hittable>(); if (hittable != null) { hittable.onHit.Invoke(); } Destroy(gameObject); } }
public override void Attack(bool mouseDown) { if (isAttacking) { setTimeSincePress(getTimeSincePress() + Time.deltaTime); if (!hasRaycasted && getTimeSincePress() >= timeToAttack) { //print("Hitting now " + getLookObj()); // Apply ItemStats damage this.DamageCondition(1); RaycastHit[] hits = Physics.CapsuleCastAll(getLookObj().transform.position, getLookObj().transform.position + getLookObj().transform.forward *range, width, getLookObj().transform.forward); foreach (RaycastHit hit in hits) { if (hit.distance <= range && !hit.collider.isTrigger && hit.collider.gameObject.tag != "Player") { // Push physics, regardless of hittable Rigidbody r; if (r = hit.collider.GetComponent <Rigidbody>()) { //print("Adding force"); // Play around with a good factor here r.AddForceAtPosition(baseDamage * getLookObj().forward * 10, getLookObj().position); r.AddForce(Vector3.up * r.mass * 350); } // Hit with hittable Hittable hittable = hit.collider.GetComponentInParent <Hittable>(); if (hittable != null) { //print("hit " + hit); hittable.Hit(baseDamage * (getCondition() / 100), getLookObj().transform.forward, damageType); } } } hasRaycasted = true; } else if (hasRaycasted && getTimeSincePress() > timeToAttack + timeToCooldown) { isAttacking = false; hasRaycasted = false; setTimeSincePress(0); } } else if (mouseDown && !isAttacking) { isAttacking = true; getPlayerAnim().SetTrigger(getControllerSide() + "Attack"); getPlayerAnim().SetInteger(getControllerSide() + "AttackNum", UnityEngine.Random.Range(0, 2)); } }
/// <summary> /// Sent when an incoming collider makes contact with this object's /// collider (2D physics only). /// </summary> /// <param name="other">The Collision2D data associated with this collision.</param> void OnCollisionEnter2D(Collision2D other) { Hittable _hittable = other.gameObject.GetComponent <Hittable>(); if (_hittable != null) { while (damage-- > 0) { _hittable.Hit(); } } Destroy(gameObject); }
public static Hittable MakeHittable(GameObject go = null) { if (go == null) { go = new GameObject("Hittable"); Rigidbody rb = go.AddComponent <Rigidbody>(); rb.isKinematic = true; } go.layer = 26; Hittable newHittable = go.AddComponent <Hittable>(); newHittable.IsEnemy = true; return(newHittable); }
void OnTriggerEnter(Collider other) { Hittable hitObject = other.GetComponent <Hittable>(); if (hitObject != null) { _monsterInRange = true; hitObject.ReactToHit(damage); } else { Debug.Log("Hit a wall"); } }