I really have no ideea how to do that . If your guys have any ideeas , pls let me know.
Here is the description : holding down Q should display a semi-transparent rectangle starting from the player’s center and pointing towards the mouse position, but not exceeding a maximum configurable length. Releasing the Q key should instantly damage all enemies within the rectangle, for a configurable amount of damage.
Create a hidden cone mesh with Collider Component attach to it
Holding Q instantiate ( or active if object pool) this hidden cone mesh.
Using empty game object to determine a root of cone by attach to it then always make root.transform x and z coordinate same as your character transform.
The length can be adjust by scale, you know what i mean, huh ?
Release the Q, check if object contact in bound or not, or simply active and check OnColliderStay.
This is what I’ve been using. You can convert this to a one-liner but I broke it down a bit to make it easier to read
float offSet = 4f; //this makes the cone cast position slightly further back to avoid missing enemies directly in front of you
float coneAngle = 0.75f;
Collider[] hits = Physics.OverlapSphere(caster.transform.position, range, enemyLayerMask); //get all colliders within sphere
hits = hits.Where(
collider => Vector3.Dot((collider.transform.position - (caster.transform.position + (-caster.transform.forward * offSet))).normalized, caster.transform.forward) > coneAngle
); //get all entities within cone based on Vector3.Dot
This is how you get the enemies you need to damage ( hits ). Then you just use a projector shining on the terrain to show the targeting angle. Create the spell’s visual effect so it looks like it’s casting in vaguely the same angle. You can program the particle system to make the angle match up exactly if you want.