private void Explode() { Analytics.CustomEvent("SuccessfulDunk", new Dictionary <string, object> { { "Zone", GameManager.GetCurrentZoneName() }, }); BallBehaviour i_ball = passController.GetBall(); ChangeState(DunkState.Explosing); if (playerController != null) { EnergyManager.DecreaseEnergy(energyPercentLostOnSuccess); } List <IHitable> i_hitTarget = new List <IHitable>(); Collider[] i_hitColliders = Physics.OverlapSphere(i_ball.transform.position, dunkExplosionRadius); int i = 0; while (i < i_hitColliders.Length) { IHitable i_potentialHitableObject = i_hitColliders[i].GetComponentInParent <IHitable>(); if (i_potentialHitableObject != null && !i_hitTarget.Contains(i_potentialHitableObject)) { i_potentialHitableObject.OnHit(i_ball, (i_hitColliders[i].transform.position - transform.position).normalized, pawnController, dunkDamages, DamageSource.Dunk); i_hitTarget.Add(i_potentialHitableObject); } i++; } ChangeState(DunkState.None); }
private void FixedUpdate() { if (inAction && !cooling) { currentHeat += heatGainPerShot; if (Overheated) { StartCoroutine(Owerheat()); return; } lineRend.enabled = true; RaycastHit hit; Vector3 origin = PlayerController.instance.cameraController.transform.position; Vector3 direction = PlayerController.instance.cameraController.transform.forward; currentHeat += heatGainPerShot; Ray ray = new Ray(origin, direction); int steps = Mathf.CeilToInt(distance); Vector3 final = origin + direction * distance; if (Physics.SphereCast(ray, 0.3f, out hit, distance)) { final = hit.point; steps = Mathf.Max(Mathf.CeilToInt(hit.distance), 2); IHitable hitable = hit.transform.GetComponent <IHitable>(); if (hitable != null && (Object)hitable != PlayerController.instance) { AttackInfo aInfo = new AttackInfo(damage, direction * 0.001f, hit.point, hit.normal); hitable.OnHit(aInfo); } } Debug.DrawLine(origin, final, Color.red, 2f); lineRend.positionCount = steps; lineRend.SetPosition(0, lineRend.transform.position); lineRend.SetPosition(steps - 1, final); for (int i = 1; i < steps - 1; i++) { Vector3 dir = Vector3.Lerp(lineRend.transform.position, final, Mathf.Floor(i) / steps); Vector3 vec = new Vector3(Random.Range(-1, 1), Random.Range(-1, 1), Random.Range(-1, 1)) * 0.1f; dir += vec; lineRend.SetPosition(i, dir); } } else { lineRend.enabled = false; } }
/// <summary> /// Checks the collison with the bullet ray and handles them /// </summary> private void DetectHit() { bool hasHit = Physics.Raycast(barrelExit.transform.position, transform.rotation * Vector3.forward, out RaycastHit hit); if (hasHit) { if (!hit.collider.gameObject.GetComponent <Enemy>()) { SpawnBulletHole(hit); } IHitable target = hit.transform.GetComponentInParent <IHitable>(); if (target == null) { if (drawLines) { BulletLines.SpawnLine(BulletLine, barrelExit.transform.position, barrelExit.transform.position + transform.rotation * Vector3.forward * 10, Color.red); } return; } HitType type = target.OnHit(this, hit); if (drawLines) { Color linecolor = Color.red; switch (type) { case HitType.MISS: linecolor = Color.red; break; case HitType.RIGHT: linecolor = Color.green; break; case HitType.UNWANTED: linecolor = Color.magenta; break; } BulletLines.SpawnLine(BulletLine, barrelExit.transform.position, barrelExit.transform.position + transform.rotation * Vector3.forward * 10, linecolor); } } else { if (drawLines) { BulletLines.SpawnLine(BulletLine, barrelExit.transform.position, barrelExit.transform.position + transform.rotation * Vector3.forward * 10, Color.red); } } }
private IEnumerator Primary() { inAction = true; if (audio) { audio.PlayOneShot(audio.clip); } Vector3 origin = PlayerController.instance.cameraController.transform.position; Vector3 direction = PlayerController.instance.cameraController.transform.forward; currentHeat += heatGainPerShot; direction = Spread(spread) * direction; Ray ray = new Ray(origin, direction); Debug.DrawRay(origin, direction, Color.red, 2f); animator.SetTrigger("fire"); lineRend.enabled = true; lineRend.SetPosition(0, lineRend.transform.position); lineRend.SetPosition(1, ray.origin + ray.direction * 5); Debug.Log("shoot"); RaycastHit[] hitInfo = Physics.RaycastAll(ray); hitInfo = hitInfo.OrderBy((x) => x.distance).ToArray(); foreach (RaycastHit hit in hitInfo) { IHitable hitable = hit.transform.GetComponent <IHitable>(); if (hitable != null && (Object)hitable != PlayerController.instance) { AttackInfo aInfo = new AttackInfo(damage, direction, hit.point, hit.normal); hitable.OnHit(aInfo); if (aInfo.blocked) { break; } } } PlayerController.instance.m_cameraRot *= Quaternion.Euler(-recoil, 0, 0); yield return(new WaitForSeconds(effectTime)); lineRend.enabled = false; yield return(new WaitForSeconds(cooldown - effectTime)); inAction = false; }
private void OnTriggerEnter(Collider other) { Collider[] i_hitColliders = Physics.OverlapBox(transform.position, meleeCollider.bounds.size / 2, Quaternion.identity); int i = 0; while (i < i_hitColliders.Length) { IHitable i_potentialHitableObject = i_hitColliders[i].GetComponent <IHitable>(); if (i_potentialHitableObject != null) { i_potentialHitableObject.OnHit(null, (other.transform.position - transform.position).normalized, spawnParent, attackDamage, DamageSource.EnemyContact); } i++; } ToggleArmCollider(false); }
IEnumerator ProjectEnemiesInRadiusAfterDelay_C(float _delay, float _radius, int _damages, DamageSource _damageSource) { if (_delay > 0) { yield return(new WaitForSeconds(_delay)); } Collider[] foundColliders = Physics.OverlapSphere(transform.position, _radius); foreach (Collider hit in foundColliders) { IHitable potentialHitableObject = hit.transform.GetComponent <IHitable>(); if (potentialHitableObject != null) { potentialHitableObject.OnHit(null, (hit.transform.position - transform.position).normalized, this, _damages, _damageSource); } } }
private void RaycastToHitWithLaser() { // First raycast pass to determine the laser length float i_closestDistance = enemyScript.laserMaxLength; RaycastHit[] i_hitObjects = Physics.SphereCastAll(transform.position, laserWidth, transform.TransformDirection(Vector3.forward), enemyScript.laserMaxLength); if (i_hitObjects.Length > 0) { foreach (var touched in i_hitObjects) { if ((touched.collider.tag == "Player" || touched.collider.tag == "Environment") && touched.distance < i_closestDistance) { i_closestDistance = touched.distance; } } } laserLength = i_closestDistance + laserWidth * 1.1f; // This is to compensate the sphere cast radius if (isLaserActive) { // Second raycast pass to determine what the laser hit and damage it RaycastHit[] i_hitObjectsWithRightLength = Physics.SphereCastAll(transform.position, laserWidth, transform.TransformDirection(Vector3.forward), i_closestDistance); { if (i_hitObjectsWithRightLength.Length > 0) { foreach (var touched in i_hitObjectsWithRightLength) { Debug.DrawRay(touched.transform.position, Vector3.up * 4, Color.green); IHitable i_potentialHitableObject = touched.collider.GetComponent <IHitable>(); if (i_potentialHitableObject != null && touched.transform != enemyScript.transform) { i_potentialHitableObject.OnHit(null, (touched.transform.position - touched.point).normalized, null, enemyScript.damagePerSecond * Time.deltaTime, DamageSource.Laser, Vector3.zero); LaserRepulsion(touched.point); GameObject i_impactFX = Instantiate(impactFX, touched.point, Quaternion.identity); i_impactFX.transform.localScale = impactFXScale; } } } } } }
private void SafeExplode() // explodes, but only touches enemies { GameObject explosionFXInstance = FeedbackManager.SendFeedback(safeExplosionFX, this).GetVFX(); explosionFXInstance.transform.localScale = new Vector3(explosionFXScale, explosionFXScale, explosionFXScale); Collider[] i_hitColliders = Physics.OverlapSphere(transform.position, explosionRadius, layersToCheckForExplosion); int i = 0; while (i < i_hitColliders.Length) { IHitable potentialHitableObject = i_hitColliders[i].GetComponent <IHitable>(); if (potentialHitableObject != null && i_hitColliders[i].gameObject.tag == "Enemy") { potentialHitableObject.OnHit(null, (i_hitColliders[i].transform.position - transform.position).normalized, null, explosionDamage, DamageSource.RedBarrelExplosion, bumpValues); } i++; } }
private void Explode() { GameObject explosionFXInstance = FeedbackManager.SendFeedback(explosionFX, this).GetVFX(); explosionFXInstance.transform.localScale = new Vector3(explosionFXScale, explosionFXScale, explosionFXScale); Collider[] i_hitColliders = Physics.OverlapSphere(transform.position, explosionRadius); int i = 0; while (i < i_hitColliders.Length) { IHitable potentialHitableObject = i_hitColliders[i].GetComponent <IHitable>(); if (potentialHitableObject != null) { potentialHitableObject.OnHit(null, (i_hitColliders[i].transform.position - transform.position).normalized, this, explosionDamage, DamageSource.RedBarrelExplosion, bumpValues); } i++; } }
protected bool RaycastAttack(Ray ray, float damage, float range) { bool output = false; RaycastHit[] hitInfo = Physics.RaycastAll(ray, range); hitInfo = hitInfo.OrderBy((x) => x.distance).ToArray(); foreach (RaycastHit hit in hitInfo) { IHitable hitable = hit.transform.GetComponent <IHitable>(); if (hitable != null && hit.distance > 0.3f) { AttackInfo aInfo = new AttackInfo(damage, ray.direction, hit.point, hit.normal); hitable.OnHit(aInfo); output = true; if (aInfo.blocked) { break; } } } return(output); }
private IEnumerator Primary() { inAction = true; if (audio) { audio.PlayOneShot(audio.clip); } Vector3 origin = PlayerController.instance.cameraController.transform.position; Vector3 direction = PlayerController.instance.cameraController.transform.forward; Ray ray = new Ray(origin, direction); Debug.DrawRay(origin, direction, Color.red, 2f); animator.SetTrigger("fire"); animator.SetInteger("Rand", attackCounter++ % ATTACK_ANIMATIONS_COUNT); //lineRend.enabled = true; //lineRend.SetPosition(0, lineRend.transform.position); //lineRend.SetPosition(1, ray.origin + ray.direction); RaycastHit[] hitInfo = Physics.SphereCastAll(origin, 1, direction, 1); foreach (RaycastHit hit in hitInfo) { IHitable hitable = hit.transform.GetComponent <IHitable>(); if (hitable != null && (Object)hitable != PlayerController.instance) { AttackInfo aInfo = new AttackInfo(damage, direction, hit.point, hit.normal); hitable.OnHit(aInfo); } } yield return(new WaitForSeconds(cooldown)); //lineRend.enabled = false; inAction = false; }
private void OnTriggerEnter(Collider other) { Vector3 colliderSize = meleeCollider.bounds.size; Collider[] i_hitColliders = Physics.OverlapBox(transform.position, colliderSize / 2, Quaternion.identity); int i = 0; while (i < i_hitColliders.Length) { IHitable i_potentialHitableObject = i_hitColliders[i].GetComponentInParent <IHitable>(); if (i_potentialHitableObject != null && i_hitColliders[i].gameObject.tag == "Player") { i_potentialHitableObject.OnHit(null, (i_hitColliders[i].transform.position - transform.position).normalized, null, attackDamage, DamageSource.EnemyContact); } if (i_hitColliders[i].gameObject.tag == "Boss_Destructible") { Destroy(i_hitColliders[i].gameObject); } i++; } ToggleArmCollider(false); }
private void UpdateBallPosition() { switch (ballInformations.state) { case BallState.Flying: ballInformations.timeFlying += Time.deltaTime; if (ballInformations.isTeleguided) { PassController i_currentPassController = GetCurrentThrower().GetComponent <PassController>(); if (i_currentPassController != null) { ballInformations.direction = (i_currentPassController.GetTarget().GetCenterPosition() - transform.position).normalized; } } else if (ballInformations.curve != null) { PassController i_currentPassController = GetCurrentThrower().GetComponent <PassController>(); List <Vector3> i_pathCoordinates = i_currentPassController.GetCurvedPathCoordinates(startPosition, i_currentPassController.GetTarget(), ballInformations.initialLookDirection, out float d); float i_curveLength; if (i_currentPassController == null) { return; } ConvertCoordinatesToCurve(i_pathCoordinates, out curveX, out curveY, out curveZ, out i_curveLength); ballInformations.maxDistance = i_curveLength; float i_positionOnCurve = ballInformations.distanceTravelled / ballInformations.maxDistance; if (ballInformations.thrower.isPlayer) { LockManager.LockTargetsInPath(i_pathCoordinates, i_positionOnCurve); if (i_positionOnCurve >= 0.95f) { ChangeState(BallState.Grounded); LockManager.UnlockAll(); } } Vector3 i_nextPosition = new Vector3(curveX.Evaluate(i_positionOnCurve + 0.1f), curveY.Evaluate(i_positionOnCurve + 0.1f), curveZ.Evaluate(i_positionOnCurve + 0.1f)); ballInformations.direction = i_nextPosition - transform.position; } if (ballInformations.moveSpeed <= 0) { ballInformations.curve = null; ChangeState(BallState.Grounded); } else { //Ball is going to it's destination, checking for collisions RaycastHit[] i_hitColliders = Physics.RaycastAll(transform.position, ballInformations.direction, ballInformations.moveSpeed * Time.deltaTime); foreach (RaycastHit raycast in i_hitColliders) { /*EnemyShield i_selfRef = raycast.collider.GetComponentInParent<EnemyShield>(); * if (i_selfRef != null) * { * if (i_selfRef.shield.transform.InverseTransformPoint(transform.position).z > 0.0) * { * FeedbackManager.SendFeedback("event.ShieldHitByBall", this); * Vector3 i_newDirection = Vector3.Reflect(ballInformations.direction, i_selfRef.shield.transform.forward); * Bounce(i_newDirection, 1); * } * }*/ IHitable i_potentialHitableObjectFound = raycast.collider.GetComponent <IHitable>(); if (i_potentialHitableObjectFound != null && !hitGameObjects.Contains(i_potentialHitableObjectFound) && !isGhostBall) { hitGameObjects.Add(i_potentialHitableObjectFound); i_potentialHitableObjectFound.OnHit(this, ballInformations.direction * ballInformations.moveSpeed, ballInformations.thrower, GetCurrentDamages(), DamageSource.Ball); SlowTimeScale(); } if (raycast.collider.isTrigger || raycast.collider.gameObject.layer != LayerMask.NameToLayer("Environment")) { break; } FeedbackManager.SendFeedback("event.WallHitByBall", raycast.transform, raycast.point, ballInformations.direction, raycast.normal); if (!ballInformations.canHitWalls) { return; } if (ballInformations.bounceCount < ballInformations.ballDatas.maxBounces && ballInformations.canBounce) //Ball can bounce: Bounce { Analytics.CustomEvent("BallBounce", new Dictionary <string, object> { { "Zone", GameManager.GetCurrentZoneName() }, }); Vector3 i_hitNormal = raycast.normal; i_hitNormal.y = 0; Vector3 i_newDirection = Vector3.Reflect(ballInformations.direction, i_hitNormal); i_newDirection.y = -ballInformations.direction.y; Bounce(i_newDirection, ballInformations.ballDatas.speedMultiplierOnBounce); return; } else //Ball can't bounce: Stop { ChangeState(BallState.Grounded); MomentumManager.DecreaseMomentum(MomentumManager.datas.momentumLossWhenBallHitTheGround); return; } } } transform.position += ballInformations.direction.normalized * ballInformations.moveSpeed * Time.deltaTime * MomentumManager.GetValue(MomentumManager.datas.ballSpeedMultiplier) * GetCurrentSpeedModifier(); ballInformations.distanceTravelled += ballInformations.moveSpeed * Time.deltaTime * MomentumManager.GetValue(MomentumManager.datas.ballSpeedMultiplier) * GetCurrentSpeedModifier(); if (ballInformations.curve == null && !ballInformations.isTeleguided && ballInformations.distanceTravelled >= ballInformations.maxDistance) { ChangeState(BallState.Grounded); } break; } }
void CheckForHit(GameObject obj) { IHitable hitableObject = obj.GetComponent <IHitable>(); hitableObject?.OnHit(damage); }