// void EnemyInfoEC() { // EnemyConsistency enemyConsistency = EnemyAnalyzer.enemyConsistency; // if (enemyConsistency != null) { // Marcador de posición estimada del enemigo Vector3 anticipatedPositionInScreen = mainCamera.WorldToViewportPoint(EnemyAnalyzer.estimatedToHitPosition); GUI.DrawTexture(new Rect( anticipatedPositionInScreen.x * Screen.width - 2, Screen.height - anticipatedPositionInScreen.y * Screen.height - 2, 10, 10), circleTexture); // Barra de vida float enemyCoreHealthForBar = enemyConsistency.CurrentHealth / enemyConsistency.maxHealth; enemyCoreHealthForBar = Mathf.Clamp01(enemyCoreHealthForBar); GUI.DrawTexture(new Rect(Screen.width / 2 + 150, Screen.height / 2 - 30, enemyCoreHealthForBar * 100f, 20), enemyHealthTexture); //GUI.Label(new Rect(Screen.width / 2 + 150, Screen.height / 2 - 30, 100f, 20), " " + enemyConsistency.CurrentHealth); // TODO: Sacar vida de la parte extra EnemyCollider enemyCollider = EnemyAnalyzer.enemyCollider; if (enemyCollider != null && enemyCollider.isTargeteable && enemyCollider.maxLocationHealth > 0) { float enemyPartHealthForBar = enemyCollider.CurrentLocationHealth / enemyCollider.maxLocationHealth; enemyPartHealthForBar = Mathf.Clamp01(enemyPartHealthForBar); GUI.DrawTexture(new Rect(Screen.width / 2 + 150, Screen.height / 2, enemyPartHealthForBar * 100f, 20), enemyHealthTexture); } // float distance = (playerIntegrity.transform.position - enemyConsistency.transform.position).magnitude; int distanceToShow = (int)distance; GUI.Label(new Rect(Screen.width / 2 + 150, Screen.height / 2, 300, 20), "Distance: " + distanceToShow, guiSkin.label); // TODO: Mostrar también velocidad del bicho float enemySpeed = (int)EnemyAnalyzer.enemyRb.velocity.magnitude; GUI.Label(new Rect(Screen.width / 2 + 150, Screen.height / 2 + 30, 300, 20), "Speed: " + enemySpeed + " m/s", guiSkin.label); // Raycast para saber si el enemigo está a tiro RaycastHit hitInfo; Vector3 enemyCentralPointPosition = EnemyAnalyzer.enemyTransform.TransformPoint(EnemyAnalyzer.enemyConsistency.centralPointOffset); Vector3 enemyDirection = enemyCentralPointPosition - cameraControl.transform.position; if (Physics.Raycast(cameraControl.transform.position, enemyDirection, out hitInfo, enemyDirection.magnitude)) { //Debug.Log(hitInfo.transform.name); EnemyCollider possibleHit = hitInfo.collider.GetComponent <EnemyCollider>(); //Debug.Log("Enemy collider: " + enemyCollider); if (possibleHit != null) { //GUI.DrawTexture(new Rect(Screen.width / 2 - 25, Screen.height / 2 - 25, 50, 50), enemyMarkerTextureRed); Vector3 enemyScreenPosition = Camera.main.WorldToViewportPoint(enemyCentralPointPosition); GUI.DrawTexture(new Rect( (enemyScreenPosition.x * Screen.width) - 25, Screen.height - (enemyScreenPosition.y * Screen.height) - 25, 50, 50), enemyMarkerTextureRed); } } } }
private void CheckCollision(Collider2D collider) { if (controller.di.hp.IsDead) { return; } if (merge.MergeWith(collider)) { return; } EnemyCollider enemy = collider.GetComponent <EnemyCollider>(); if (enemy) { if (guard.GuardAgainst(enemy)) { return; } if (stomp.StompOn(enemy)) { return; } if (enemy.attack) { ReceieveDamageFrom(enemy); } } }
// AffectedByPulseAttack GetElementsOnReachOfPulseAttack(float pulseReach, float pulseRadius) { // AffectedByPulseAttack affectedByPulseAttack = new AffectedByPulseAttack(); // Collider[] collidersOnReach = Physics.OverlapSphere(transform.position, pulseReach); // for (int i = 0; i < collidersOnReach.Length; i++) { //Si no entra en el ángulo, siguiente Vector3 pointFromPlayer = collidersOnReach[i].transform.position - transform.position; if (Vector3.Angle(pointFromPlayer, transform.forward) > pulseRadius) { continue; } // Chequemamos primero por enemy colliders EnemyCollider enemyCollider = collidersOnReach[i].GetComponent <EnemyCollider>(); if (enemyCollider != null) { affectedByPulseAttack.affectedEnemyColliders.Add(enemyCollider); } // Después enemy consistencies EnemyConsistency enemyConsistency = collidersOnReach[i].GetComponent <EnemyConsistency>(); if (enemyConsistency == null) { enemyConsistency = collidersOnReach[i].GetComponentInParent <EnemyConsistency>(); } if (enemyConsistency != null) { affectedByPulseAttack.affectedEnemyConsistencies.Add(enemyConsistency); } // WeakPoint weakPoint = collidersOnReach[i].GetComponent <WeakPoint>(); if (weakPoint != null) { Debug.Log("Adding weakpoint"); affectedByPulseAttack.affectedWeakPoints.Add(weakPoint); } // Terrenos destruibles DestructibleTerrain destructibleTerrain = collidersOnReach[i].GetComponent <DestructibleTerrain>(); if (destructibleTerrain == null) { destructibleTerrain = collidersOnReach[i].GetComponentInParent <DestructibleTerrain>(); } if (destructibleTerrain != null) { affectedByPulseAttack.affectedDestructibleTerrains.Add(destructibleTerrain); } // Y por último rigidbodies // Estos solo deberían entrar en la lista si no ha cuajado arriba Rigidbody rigidbody = collidersOnReach[i].GetComponent <Rigidbody>(); if (rigidbody != null && enemyConsistency == null) { affectedByPulseAttack.affectedRigidbodies.Add(rigidbody); } } return(affectedByPulseAttack); }
// void SpawnBulletHole(Vector3 point, Vector3 normal, GameObject objectToParent) { // PlayerIntegrity playerIntegrity = objectToParent.GetComponent <PlayerIntegrity>(); // Error control vago if (bulletHolePrefab == null || playerIntegrity != null) { return; } // Decidimos si crear agujero de bala o churrete de sangre EnemyCollider enemyCollider = objectToParent.GetComponent <EnemyCollider>(); WeakPoint weakPoint = objectToParent.GetComponent <WeakPoint>(); GameObject prefabToUse = (enemyCollider != null || weakPoint != null) ? bulletHoleBugPrefab : bulletHolePrefab; // Y lo creamos GameObject newBulletHole = Instantiate(prefabToUse, point, Quaternion.identity); newBulletHole.transform.rotation = Quaternion.LookRotation(newBulletHole.transform.forward, normal); // Lo movemos un pelin para evitar el z clipping newBulletHole.transform.position += newBulletHole.transform.up * 0.01f; newBulletHole.transform.SetParent(objectToParent.transform); }
// public void RemoveTargeteablePart(EnemyCollider damagedPart) { // targetableColliders.Remove(damagedPart); // springCamera.SwitchTarget(transform); }
// Start is called before the first frame update void Start() { //gigaWormBehaviour = GetComponentInParent<GigaWormBehaviour>(); currentHealthPoints = maxHealthPoints; carolBaseHelp = FindObjectOfType <CarolBaseHelp>(); enemyCollider = GetComponent <EnemyCollider>(); impactInfoManager = FindObjectOfType <ImpactInfoManager>(); }
// Use this for initialization void Start() { vidas = 2; //caminaAnimacion = GetComponent <Animator>(); player = FindObjectOfType<MovimientoPersonajePrincipal>(); enemyRigidBody = GetComponent<Rigidbody2D>(); enemyCollider = GetComponent<EnemyCollider>(); }
private void GetCachedReferences() { enemyMovement = GetComponent <EnemyMovement>(); enemyHealth = GetComponent <EnemyHealth>(); enemyCollider = GetComponent <EnemyCollider>(); enemyCurrency = GetComponent <EnemyCurrency>(); bank = FindObjectOfType <Bank>(); }
private void addScript() { EnemyCollider cardCollision = this.cardObj.gameObject.AddComponent <EnemyCollider>(); CardEnemy card = this.cardObj.gameObject.AddComponent <CardEnemy>(); card.cardData = this.cardData; card.cardObj = this.cardObj; card.cardState = this.cardState; }
private void CheckGroundByRaycast() { RaycastHit2D[] rays = new RaycastHit2D[5]; var rayCount = EnemyCollider.Raycast(Vector2.down, rays); _onGround = rayCount > 0 && rays.Any(r => r.collider != null && r.collider.CompareTag(TagNames.GROUND) && r.distance < Size.y + 0.1f); }
// TODO: Ajustarlo para que trabaje con casos sin rigidbody y/o enemyconsistency public static void Assign(Transform enemyReference) { enemyTransform = enemyReference; enemyRb = enemyReference.GetComponent <Rigidbody>(); // Chequeo extra para multipartes if (enemyRb == null) { enemyRb = enemyReference.GetComponentInParent <Rigidbody>(); } // Chequeo para gusano grande. Debería ser el de la cabeza el que coja if (enemyRb == null) { enemyRb = enemyReference.GetComponentInChildren <Rigidbody>(); // Para cuando cambias entre partes del cuerpo if (enemyRb == null) { enemyRb = enemyReference.parent.GetComponentInChildren <Rigidbody>(); } // else { enemyTransform = enemyRb.transform; } } // enemyConsistency = enemyReference.GetComponent <EnemyConsistency>(); // Chequeo extra para las body parts if (enemyConsistency == null) { enemyConsistency = enemyReference.GetComponentInParent <EnemyConsistency>(); } // Para el gusano grande if (enemyConsistency == null) { enemyConsistency = enemyReference.parent.GetComponentInChildren <EnemyConsistency>(); } // Chequeo para los componentes que no lo tienen, como los WeakPoints // TODO: Ponerselos más adelante y quitar esto if (enemyConsistency != null) { enemyConsistency.SetCollidersPenetrationColors(); } // enemyCollider = enemyReference.GetComponent <EnemyCollider>(); // targeteable = enemyReference.GetComponent <Targeteable>(); // Chequeo extra para las body parts if (targeteable == null) { targeteable = enemyReference.GetComponentInParent <Targeteable>(); } isActive = true; }
public bool GuardAgainst(EnemyCollider enemy) { if (enemy.guardable && IsGuardingAgainst(enemy.boxCollider)) { Vector2 recoilForce = enemy.guardable.GetRecoilFor(controller); // controller.di.sfx.PlayGuard(); //AudioSingleton.PlaySound(AudioSingleton.Instance.clips.guard); controller.di.stateMachine.SetRecoilState(recoilForce); enemy.guardable.HandleGuarded(controller); return(true); } return(false); }
// Lo ponemos para ver que falla con las colisiones entre cuerpos // Ojo que alguna la pillará por duplicado protected virtual void OnCollisionEnter(Collision collision) { // Estas no las queremos chequear aqui Bullet bullet = collision.collider.GetComponent <Bullet>(); // Chequeamos diferencia de velocidades para ver si solo es fricción u hostiazo //Vector3 velocityOffset = previousVelocity - rb.velocity; // De momento diferencia de 1 if (bullet == null && bodyBehaviour.OfFoot /*&& collision.collider.tag != "Sand"*/) { // Rigidbody otherRb = collision.collider.GetComponent <Rigidbody>(); float impactForce = GeneralFunctions.GetCollisionForce(rb, otherRb); //impactForce = GeneralFunctions.GetBodyKineticEnergy(rb); if (otherRb != null || CheckDrasticChangeInAcceleration(1)) { //Debug.Log("Hitting " + collision.transform.name + " with " + impactForce + " force"); ReceiveImpact(impactForce, collision.contacts[0].point); // //receivedStrongImpact = true; } } // TODO: Está duplicado aqui y en EnemyCollider // Ver como va else if (bullet != null) { //Debug.Log("Procesado en EnemyConsistency"); EnemyCollider bodyPart = collision.GetContact(0).thisCollider.GetComponent <EnemyCollider>(); //Debug.Log("Collider: " + collision.collider); float diameter = bullet.diameter; Rigidbody bulletRb = bullet.GetComponent <Rigidbody>(); float penetrationValue = GeneralFunctions.Navy1940PenetrationCalc(bulletRb.mass, diameter, bulletRb.velocity.magnitude); //Debug.Log("Penetration value: " + penetrationValue + ", mass: " + bulletRb.mass + // ", diameter: " + diameter + ", velocity: " + bulletRb.velocity.magnitude); float penetrationResult = Mathf.Max(penetrationValue - bodyPart.armor, 0); //Debug.Log(penetrationResult + ", " + penetrationValue + ", " + bodyPart.armor); // Pasamos en qué proporción ha penetrado if (penetrationResult > 0) { penetrationResult = 1 - (bodyPart.armor / penetrationValue); } //Debug.Log("Pen proportion: " + penetrationResult); // ReceiveProyectileImpact(penetrationResult, collision.GetContact(0).point, bulletRb); } }
public bool StompOn(EnemyCollider enemy) { if (dealDamageOnStomp && stompCollider.CanStomp(enemy.boxCollider)) { Vector2 stompRecoil = enemy.stompable.GetStompRecoil(); // controller.di.sfx.PlayGuard(); //AudioSingleton.PlaySound(AudioSingleton.Instance.clips.guard); controller.di.physics.velocity.Value = new Vector2( stompRecoil.x, controller.di.physics.gravity.JumpVelocity(stompRecoil.y) ); enemy.stompable.HandleStomped(controller); return(true); } return(false); }
private void ReceieveDamageFrom(EnemyCollider enemy) { // TODO: move to player damage? Vector2 pushVector = enemy.attack.GetRecoilFor(controller); if (vulnerability.IsVulnerable()) { damage.TakeDamage(enemy.attack.GetDamage(), pushVector); } else { damage.TakeDamage(0, pushVector); } enemy.attack.HandleCollisionAttack(controller); }
/// <summary> /// /// </summary> /// <returns></returns> bool ComradeInPath() { RaycastHit hitInfo; if (Physics.Raycast(shootPoint.position, shootPoint.forward, out hitInfo)) { EnemyCollider enemyCollider = hitInfo.transform.GetComponent <EnemyCollider>(); if (enemyCollider != null) { // Debug.Log("Comrade " + enemyCollider.gameObject.name + " in path"); return(true); } } return(false); }
// Use this for initialization void Awake() { random = new System.Random(); forceStrength = random.Next(1, 5); //Fill list of enabled children enabledChildren = new List <Transform>(); enabledChildren.Add(headEnemy.transform); enabledChildren.AddRange(enableDepths()); foreach (Transform child in enabledChildren) { EnemyCollider enemyCollider = child.gameObject.AddComponent <EnemyCollider>(); enemyCollider.explosionPrefab = Game.instance.enemyExplosionPrefab; } Game.instance.enemySpawned(enabledChildren.Count); }
// bool EnemyOnSight(Vector3 enemyPosition) { // RaycastHit hitInfo; Vector3 direction = enemyPosition - transform.position; // if (Physics.Raycast(transform.position, direction, out hitInfo, direction.magnitude)) { //Debug.Log("Object 'on sight': " + hitInfo.transform); EnemyCollider enemyCollider = hitInfo.transform.GetComponent <EnemyCollider>(); if (enemyCollider != null) { return(true); } EnemyConsistency enemyConsistency = hitInfo.transform.GetComponent <EnemyConsistency>(); if (enemyConsistency != null) { return(true); } } // return(false); }
// public void GenerateExplosion() { // if (exploding) { return; } else { exploding = true; } // Primero aplicamos la onda de choque // Vamos a hacer que este daño vaya contra la "estrucura" Collider[] affectedColliders = Physics.OverlapSphere(transform.position, shockWaveRange); // for (int i = 0; i < affectedColliders.Length; i++) { // Vector3 affectedColliderDirection = affectedColliders[i].transform.position - transform.position; float receivedBlastForce = explosionForce / (1 + Mathf.Pow(affectedColliderDirection.magnitude, 2)); Vector3 blastForceWithDirection = affectedColliderDirection.normalized * receivedBlastForce; // PlayerIntegrity playerIntegrity = affectedColliders[i].GetComponent <PlayerIntegrity>(); if (playerIntegrity != null) { playerIntegrity.ReceiveBlastDamage(blastForceWithDirection); } // EnemyCollider enemyCollider = affectedColliders[i].GetComponent <EnemyCollider>(); if (enemyCollider != null) { enemyCollider.ReceivePulseDamage(blastForceWithDirection); } // Después enemy consistencies EnemyConsistency enemyConsistency = affectedColliders[i].GetComponent <EnemyConsistency>(); if (enemyConsistency == null) { enemyConsistency = affectedColliders[i].GetComponentInParent <EnemyConsistency>(); } if (enemyConsistency != null) { enemyConsistency.ReceivePulseDamage(blastForceWithDirection); } // DestructibleTerrain destructibleTerrain = affectedColliders[i].GetComponent <DestructibleTerrain>(); if (destructibleTerrain != null) { destructibleTerrain.ReceivePulseImpact(blastForceWithDirection); } // Aplicamos fuerza directa a los rigidbodies que no son el player ni los enemigos // Estos se lo gestionan en la funcióbn de recibir daño de explosión Rigidbody rigidbody = affectedColliders[i].GetComponent <Rigidbody>(); if (rigidbody != null && enemyConsistency == null && playerIntegrity == null && rigidbody != proyectileRb) { rigidbody.AddForce(blastForceWithDirection / 1000); } } // if (generatesFragments) { GenerateFragments(fragmentsPerHeight, fragmentsPerWidth, 1 / 2); } // //GeneralFunctions.PlaySoundEffect(audioObjectManager, explosionClip); if (audioObjectManager != null) { audioObjectManager.CreateAudioObject(explosionClip, transform.position); } // //Destroy(gameObject); //proyectileRb.velocity = Vector3.zero; //bulletPool.ReturnBullet(gameObject); bulletScript.ReturnBulletToPool(); }
// protected void GenerateImpact(Collider collider, Vector3 hitPoint, Vector3 hitNormal, float dt = 0) { // transform.position = hitPoint; GameObject particlesToUse = impactParticlesPrefab; AudioClip clipToUse = null; // Chequeamos si ha impactado a un enemigo y aplicamos lo necesario EnemyCollider enemyCollider = collider.GetComponent <EnemyCollider>(); if (enemyCollider != null) { enemyCollider.ReceiveBulletImpact(rb, hitPoint); particlesToUse = impactOnBugParticlesPrefab; clipToUse = impactOnEnemy; // TODO: Buscar otro sitio donde ponerlo // Aquí no suena porque se destruye el objeto //GeneralFunctions.PlaySoundEffect(audioSource, impactOnEnemy); //bulletSoundManager.CreateAudioObject(impactOnEnemy, transform.position); } // Y el player, joputa PlayerIntegrity playerIntegrity = collider.GetComponent <PlayerIntegrity>(); if (playerIntegrity != null) { clipToUse = impactOnPlayer; playerIntegrity.ReceiveImpact(transform.position, gameObject, rb, hitNormal); //GeneralFunctions.PlaySoundEffect(audioSource, impactOnPlayer); //bulletSoundManager.CreateAudioObject(impactOnPlayer, transform.position); // //Rigidbody playerRB = playerIntegrity.gameObject.GetComponent<Rigidbody>(); //playerRB.AddForce(rb.velocity * rb.mass, ForceMode.Impulse); } // Weakpoints // TODO: Gestionarlos mejor WeakPoint weakPoint = collider.GetComponent <WeakPoint>(); if (weakPoint != null) { clipToUse = impactOnEnemy; particlesToUse = impactOnBugParticlesPrefab; weakPoint.ReceiveBulletImpact(rb, this); } // Efecto de sonido if (clipToUse != null) { bulletSoundManager.CreateAudioObject(clipToUse, transform.position, 0.1f); } // Partículas if (particlesToUse != null) { GameObject impactParticles = Instantiate(particlesToUse, hitPoint, Quaternion.identity); SpawnBulletHole(hitPoint, hitNormal, collider.gameObject); Destroy(impactParticles, 2); } // TODO: Ver por qué nos hacía falta esto // Si es explosiva gestionamos la destrucción ahí // Y si es player lo gestionams en player if (explosiveBullet == null && playerIntegrity == null) { //Debug.Log("Not explosive component, destroying object"); // Destroy(gameObject); ReturnBulletToPool(); // TODO: Hcaerlo mas limpio //if(dangerousEnough) // bulletPool.RemoveDangerousBulletFromList(gameObject); } }
protected virtual void Start() { wallHitBackPos = transform.position; enemyCollider = GetComponent <EnemyCollider>(); }