public override void fire(SpellMod modifiers, Vector3 firePoint, Vector3 target) { GameObject temp = Instantiate(projectile) as GameObject; temp.transform.position = firePoint; ISpellCollision spellScript = temp.GetComponent <ISpellCollision>(); spellScript.setModifiers(modifiers); Rigidbody projectRigid = temp.GetComponent <Rigidbody>(); projectRigid.velocity = (target - firePoint).normalized * 20; }
public override void fire(SpellMod modifiers, Transform firePoint, Camera mainCam) { GameObject temp = Instantiate(projectile) as GameObject; temp.transform.position = mainCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, mainCam.nearClipPlane)); ISpellCollision spellScript = temp.GetComponent <ISpellCollision>(); spellScript.setModifiers(modifiers); Rigidbody projectRigid = temp.GetComponent <Rigidbody>(); projectRigid.velocity = mainCam.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0)).direction * 20; }
public override void fire(SpellMod modifiers, Transform firePoint, Camera mainCam) { GameObject temp = Instantiate(projectile, mainCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, mainCam.nearClipPlane)) - mainCam.transform.forward.normalized * 10, firePoint.rotation); RaycastHit[] hits; ISpellCollision spellCollision = temp.GetComponent <ISpellCollision>(); temp.GetComponent <Rigidbody>().velocity = mainCam.transform.forward.normalized * 500; hits = Physics.SphereCastAll(mainCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, mainCam.nearClipPlane)), 0.5f, mainCam.transform.forward); Debug.DrawRay(mainCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, mainCam.nearClipPlane)), mainCam.transform.forward); if (hits.Length > 0) { hits = raycastSort(hits, firePoint.position); foreach (RaycastHit hit in hits) { if (hit.collider.tag == "Enemy") { HealthControl collidedHealth = hit.collider.GetComponent <HealthControl>(); collidedHealth.takeDamage(modifiers.damage * modifiers.damagePercent); if (modifiers.dot) { collidedHealth.applyDot(modifiers.dotTick, modifiers.dotLength); } } else if (hit.collider.tag == "EnemyAttack") { Destroy(hit.collider.gameObject); } else if (hit.collider.gameObject.layer == 0) { //modifiers.range = (hit.point - temp.transform.position).magnitude / 250; return; } } spellCollision.setModifiers(modifiers); } }