Raycasting for custom projectile logic

Forum Rewards
Every new forum post gives the author +10 coins. You can also reward great posts from other users.
Min donation: 10 coins Author gets 50%
Trying to make a 'Laser' spell. Does anyone have a snippet for a multi-hit raycast? I want the beam to pass through the first mob and hit the second one, but lose 50% damage per hit. My current script just stops at the first collision.
Don't forget to add a 'max_hits' limit, or a single laser into a crowded mob farm will spike your server CPU to 100% lol.
You need to use Physics.RaycastAll(). It returns an array of hits sorted by distance. Then just iterate through them and apply your damage reduction logic in a loop.

Post a Reply

Formatting: [b]bold[/b], [i]italic[/i], [u]underline[/u], [code]code[/code], [quote]quote[/quote]