void OnTriggerEnter2D(Collider2D other) { // if colliding with an enemy, deal damage play hit animation if (other.CompareTag("Enemy") && !deactivating) { Burnable burnableScript = other.GetComponent <Burnable>(); if (burnableScript != null) { burnableScript.Burn(baseDamage); } else { Debug.LogError("Enemy not burning."); } if (owner != null) { PlayerStatus playerStatusReference = owner.GetComponent <PlayerStatus>(); if (playerStatusReference != null) { playerStatusReference.gainEnergy(1f); } } speed = 0f; StartCoroutine(Deactivate()); } else if (other.transform.parent != null) { if (other.transform.parent.gameObject.CompareTag("bat")) { other.transform.parent.gameObject.SetActive(false); StartCoroutine(Deactivate()); } } }
void CheckBurnablePossibilities() { RaycastHit hit; RaycastHit torchHit; Vector3 endPoint = transform.TransformDirection(Vector3.forward); bool rayHitSomething = CastBurnableCheckRay(endPoint, out hit); bool rayHitTorch = CastTorchCheckRay(endPoint, out torchHit); if (rayHitSomething && !rayHitTorch) { //Vector3 point = hit.point; targetBurnable = GetBurnableObject(hit); } else if (rayHitSomething && rayHitTorch && torchHit.distance > hit.distance) { targetBurnable = GetBurnableObject(hit); } else { if (previouslyHitBurnable != null) { previouslyHitBurnable.SetMaterial(fireConfig.BurnableDefaultMaterial); } targetBurnable = null; /*Vector3 point = transform.position + transform.forward * fireConfig.MaxDistance; * point.y = 0f;*/ } DebugRayCast(hit, rayHitSomething); }
// Start is called before the first frame update void Awake() { burnable = GetComponent <Burnable>(); spriteRenderer = GetComponent <SpriteRenderer>(); originalSprite = spriteRenderer.sprite; Initialize(); }
private void Start() { m_Fires = this.gameObject.transform.GetChild(0).gameObject; m_SoundFire = GetComponent <AudioSource>(); m_Burnable = GetComponent <Burnable>(); m_Fires.SetActive(false); }
protected override void Start() { base.Start(); if (rightHandFull) { rightHand.holderController = this; } _burnable = GetComponent <Burnable>(); _burnable.OnBurn += OnBurn; }
/// <summary> /// Checks the colliding objects if they can burn and stops the fire from falling once it hits something /// </summary> /// <param name="collision">The object wich the Fire collided with</param> private void OnCollisionEnter(Collision collision) { Burnable bur = collision.gameObject.GetComponentInChildren <Burnable>(); if (bur != null) { Rigidbody rb = GetComponent <Rigidbody>(); rb.isKinematic = true; rb.useGravity = false; rb.constraints = RigidbodyConstraints.FreezeAll; bur.Burn(this); } }
public void OnTriggerEnter2D(Collider2D other) { Burnable burnable = other.GetComponent <Burnable>(); if (GetComponent <SelfDestruction>() == null && burnable && !burnable.IsBurning()) { HeatmapEvent.Send("BurnedVegetation2", transform.position, Time.timeSinceLevelLoad); KHeatmap.Log("BurnedVegetation2", transform.position); burnable.Burn(); } //if (other.GetComponent<ChargeRecharge>()) //boostEffect(true); }
//Server call only, no call on client. //ServerCallback is similar to Server but doesn't generate a warning when called on client. void OnTriggerEnter(Collider other) { if (other.tag == "Shield") { other.GetComponent <Shield>().Break(); Destroy(GetComponent <SphereCollider>(), 0); } else if (other.tag == "Spell_Interactable") { SpellInteractable si = other.GetComponent <SpellInteractable>(); Burnable b = other.GetComponent <Burnable>(); if (si != null) { si.Trigger("fireball"); } if (b != null) { b.Burn(); } Destroy(GetComponent <SphereCollider>(), 0); } else if (other.tag == "Enemy") { EnemyAI enemy = other.GetComponent <EnemyAI>(); CasterAI ci = other.GetComponent <CasterAI>(); if (enemy != null) { enemy.TakeDamage("fire", damage); } if (ci != null) { ci.TakeDamage("fire", damage); } } else if (other.tag == "Player") { Player player = other.GetComponent <Player>(); if (player != null) { player.WeaponHit(damage); } } Rigidbody r = other.GetComponent <Rigidbody>(); if (r != null) { r.AddExplosionForce(explosionForce, transform.position, 2f); } }
void OnCollisionTick(Burnable otherObject) { if (otherObject.isBurning && otherObject.canSpreadFireToOthers) { this.temperature = Mathf.Min(inflammationTreshold, this.temperature + otherObject.burnIntensity / this.heatResistance); if (this.health > 0 && this.isFlammable) { if (!this.isBurning && this.temperature >= this.inflammationTreshold) { StartFire(); } } } }
// TODO: find a way so we don't have this many getcomponents private void BurnEffect() { colliders = Physics2D.OverlapCircleAll(transform.position, radius); if (colliders.Length >= 1) { for (int i = 0; i < colliders.Length; i++) { Burnable adjucantBurnable = colliders[i].GetComponent <Burnable>(); if (adjucantBurnable != null && !adjucantBurnable.burning && !colliders[i].isTrigger) { adjucantBurnable.Burn(); } _obj.Hurt(5); } } }
private void SpreadBurn() { Collider2D[] hit = Physics2D.OverlapCircleAll(parent.transform.position, 2f, burnableLayerMask); foreach (Collider2D target in hit) { //Debug.Log(target.gameObject.name); //skip the target that points to this gameobject if (target.gameObject == this.gameObject) { continue; } else { if (target.gameObject.tag == "Burnable") { Burnable burnable = target.gameObject.transform.GetChild(0).GetComponent <Burnable>(); burnable.StartBurning(); } } } }
private void UpdateBurnables() { //loop through the burnables array to create new burnables for (int i = 0; i < maxBurnables; i++) { Burnable component = burnables[i].gameObject.transform.GetChild(0).GetComponent <Burnable>(); if (component.isBurning) { //do not need to reposition it. just place a new one elsewhere Vector2 oldPosition = new Vector2(burnables[i].transform.position.x + 200f, burnables[i].transform.position.y); Vector2 newPosition = RepoBurnable(oldPosition); GameObject newBurnable = ChooseBurnable(); newBurnable.GetComponent <Transform>().position = newPosition; burnables[i] = Instantiate(newBurnable, newPosition, Quaternion.identity, GameObject.Find("Burnables").transform) as GameObject; continue; } if (WithinActionField(burnables[i].transform.position)) { //do nothing } else { //not within the action field //delete the ground sprite and place a new one that is within the field GameObject toDestroy = burnables[i]; Vector2 newPosition = RepoBurnable(burnables[i].transform.position); GameObject newBurnable = ChooseBurnable(); newBurnable.GetComponent <Transform>().position = newPosition; burnables[i] = Instantiate(newBurnable, newPosition, Quaternion.identity, GameObject.Find("Burnables").transform) as GameObject; Destroy(toDestroy); } } }
private void OnTriggerStay(Collider collision) { if (collision.gameObject.CompareTag("Tree") || collision.gameObject.name == "BurningHouse" || collision.gameObject.name == "BurningHouse(Clone)") { m_FireScript = collision.gameObject.GetComponentInChildren <Fire>(); Fires = collision.gameObject.GetComponent <HouseDestruction>(); m_Burn = collision.gameObject.GetComponent <Burnable>(); if (m_FireScript != null) { if (collision.gameObject.CompareTag("Tree")) { Destroy(m_FireScript.gameObject); } } else if (Fires != null) { m_Burn.isOnFire = false; Fires.m_Fires.SetActive(false); Fires.m_StartDestruction = false; Fires.m_SoundFire.Stop(); } } }
private void Interact(Burnable burnable) { burnable.UseObject(this); }
// PlayerUpdate needs to be called by Playermanager to fix Execution order! public void Update() { float speed = stats.CurrentSpeed; Vector2 old = aim; aim = new Vector2(inputRequester.InputAxis(EInputAxis.viewHorizontal, stats.InputID), -inputRequester.InputAxis(EInputAxis.viewVertical, stats.InputID)).normalized; if (aim.magnitude == 0) { aim = old; } if (hook.hookState == HookState.hooked) { float vx = rigidbody.velocity.x; playerBody.transform.rotation = Quaternion.identity; playerBody.transform.Rotate(Vector3.up, Mathf.Clamp(-rigidbody.velocity.x * 30, -90, 90) + 90); playerBody.transform.Rotate(Vector3.forward, .8f * Vector2.Angle(vx >= 0?Vector2.right:Vector2.left, rigidbody.velocity)); } else { playerBody.transform.rotation = Quaternion.Euler(0, Mathf.Clamp(-rigidbody.velocity.x * 30, -90, 90) + 90, 0); } if (inputRequester.InputButtonDown(EInputButtons.RB, stats.InputID)) { if (hook.hookState == HookState.hooked) { //playerBody.rig.velocity = new Vector3(0, 0); playerBody.rig.AddForce(playerBody.rig.velocity.normalized * swingForce + Vector2.up * swingForce * 0.25f); // playerBody.rig.AddForce((hook.transform.position - playerBody.rig.transform.position).normalized * pullForce); //playerBody.rig.AddForce((hook.transform.position - playerBody.rig.transform.position).normalized * pullForce); hook.hookState = HookState.returning; } else if (playerBody.IsGrounded()) { playerBody.rig.velocity = new Vector3(playerBody.rig.velocity.x, 0); playerBody.rig.AddForce(Vector3.up * jumpForce); } } if (inputRequester.InputAxis(EInputAxis.triggerLeft, stats.InputID) > .1f) { //shoot here if (player.attackTimer <= 0) { playerBody.Attack(); player.source.PlayOneShot((player.Team == Team.Sand?player.sShovel:player.fSwing), .2f); var rot = Quaternion.Euler(0, 0, Vector2.SignedAngle(Vector2.right, aim)); Instantiate(player.Team == Team.Sand?player.attackPart:player.attackPart2, playerBody.transform.position, rot); Instantiate(player.splashPart, playerBody.transform.position, rot); for (float a = -20f; a < 20f; a += 4f) { var hit = Physics2D.Raycast(playerBody.transform.position + Quaternion.Euler(0, 0, a) * aim, Quaternion.Euler(0, 0, a) * aim, 5f, LayerMask.GetMask("Player", "Environment")); if (hit) { var pb = hit.transform.GetComponent <PlayerBody>(); if (pb != null) { pb.GetHit(playerBody); Debug.DrawRay(playerBody.transform.position, Quaternion.Euler(0, 0, a) * aim * 5f, Color.red, 2f); break; } else { Debug.DrawLine(playerBody.transform.position, hit.point, Color.green, 2f); } } Debug.DrawRay(playerBody.transform.position + Quaternion.Euler(0, 0, a) * aim, Quaternion.Euler(0, 0, a) * aim * 100f, Color.white, 2f); // check if hitting burnable object var burnableHit = Physics2D.Raycast(playerBody.transform.position + Quaternion.Euler(0, 0, a) * aim, Quaternion.Euler(0, 0, a) * aim, 5f, LayerMask.GetMask("Player", "Burnable")); if (burnableHit) { Burnable b = burnableHit.transform.GetComponent <Burnable>(); Debug.Log(burnableHit.transform.gameObject.name); if (b != null) { switch (player.Team) { case Team.Sand: b.RemoveBurn(1); break; case Team.Fire: b.InflictBurn(1); break; case Team.LastIndex: break; default: break; } } } } player.attackTimer = player.stats.CurrentAttackSpeed; } } Vector3 position = playerBody.rig.transform.position; float xVel = playerBody.rig.velocity.x; if (!playerBody.IsGrounded()) { float prev = xVel; xVel = Mathf.MoveTowards(xVel, inputRequester.InputAxis(EInputAxis.movementHorizontal, stats.InputID) * speed, Time.deltaTime * 20); if (hook.hookState == HookState.hooked && Mathf.Abs(xVel) < Mathf.Abs(prev)) { xVel = prev; } } else { xVel = Mathf.MoveTowards(xVel, inputRequester.InputAxis(EInputAxis.movementHorizontal, stats.InputID) * speed, Time.deltaTime * 40); if (Mathf.Abs(xVel) > .2) { Instantiate(walkDust, playerBody.transform.position + Vector3.down * .5f, Quaternion.identity); } } playerBody.rig.velocity = new Vector3(xVel, playerBody.rig.velocity.y); if (inputRequester.InputButtonDown(EInputButtons.LB, stats.InputID)) { if (hook.hookState == HookState.hooked) { hook.PullToHook(); playerBody.rig.AddForce(Vector3.up * jumpForce * 0.5f); // playerBody.rig.AddForce(playerBody.rig.velocity.normalized * pullForce); playerBody.rig.AddForce((hook.transform.position - playerBody.rig.transform.position).normalized * pullForce); //playerBody.rig.AddForce((hook.transform.position - playerBody.rig.transform.position).normalized * pullForce); hook.hookState = HookState.returning; } if (hook.hookState == HookState.stored) { hook.ShootHook(aim.normalized); } } if (playerBody.transform.position.y < -25) { GameManager.Instance.RespawnPlayer(this.GetComponent <Player>()); } }