/** LaunchSpell : public override void Method * The LauncheSpell Method is called by the abstract Class Classe when the player press the key associated to the spell. * First at all, we launch the mother method to initialize the spell launching. If the spell is Launcheable, we find a target point for our projectile. * If the RayCast does not intercept a collider, the spell can not be launched. * After that, we instantiate a fireball, make it look at the target, apply a force to it and launche the particle system associated to the prefab. * The particularity of this instantiation is that the fireball appears on a circle in the sky at random coords, upper the target Point. * Finally, we call the OnSpellLaunched method in the mother class. **/ public override void LaunchSpell() { if (!IsSpellLauncheable()) { return; } RaycastHit hit; bool hasFoundHitPoint = Physics.Raycast(PosHelper.GetOriginOfDetector(transform), _cameraPlayer.transform.forward, out hit, Mathf.Infinity, Physics.DefaultRaycastLayers, QueryTriggerInteraction.Ignore); if (hasFoundHitPoint) { base.LaunchSpell(); TargetOfSolarBurn = hit.point; } else { return; } Vector2 pointInCircle = Random.insideUnitCircle.normalized * 8; Vector3 v = new Vector3(TargetOfSolarBurn.x + pointInCircle.x, TargetOfSolarBurn.y + 15, TargetOfSolarBurn.z + pointInCircle.y); Instantiate(throwable, v, new Quaternion(), this.transform); base.OnSpellLaunched(); }
/// <summary> /// LaunchProjectile method implemented by IProjectile /// This target can be a HitPoint from a raycast or a point on the line from the player to the /// Camera.trasnform.forward (i.e. is the raycast does not intercept an entity) /// After that, we instantiate a Projectile, make it look at the target /// Apply a force to it and launch the particle system associated to the prefab (if exists) /// </summary> public virtual void LaunchProjectile() { Camera cameraPlayer = launcher.GetComponentInChildren <Camera>(); Vector3 target; RaycastHit hit; bool hasFoundHitPoint = Physics.Raycast(PosHelper.GetOriginOfDetector(launcher), cameraPlayer.transform.forward, out hit, Mathf.Infinity, Physics.DefaultRaycastLayers, QueryTriggerInteraction.Ignore); if (hasFoundHitPoint) { target = hit.point; } else { target = transform.position + cameraPlayer.transform.forward * 10; } transform.LookAt(target); GetComponent <Rigidbody>().AddForce(transform.forward * projectileSpeed); ParticleSystem particles = GetComponent <ParticleSystem>(); if (particles != null) { particles.Play(); } }
/** IsSpellLauncheable(), public override bool method * The solar burn spell is launcheable only on ground surfaces. * First we check in a Raycastall if the player is aiming at the ground. * If it is, and if the base.IsSpellLauncheable() is true, then you can cast the spell. **/ public override bool IsSpellLauncheable() { _playerTargetingFloor = false; RaycastHit[] hits = Physics.RaycastAll(PosHelper.GetOriginOfDetector(transform), _cameraPlayer.transform.forward, Mathf.Infinity); for (int i = 0; i < hits.Length; i++) { if (hits[i].collider.gameObject.tag == "Floor" || hits[i].collider.gameObject.name == "Ground") { _playerTargetingFloor = true; break; } } return(base.IsSpellLauncheable() && _playerTargetingFloor); }