Piercing ray cast? [Solved]

how would I make a ray cast that piercies players? It is easy to make a ray cast deal damage on impact to one player but how would I make it so it can pass through and damage multiple players?

Edit: after some thinking, I think I came up with something. Basically, I set a variable to the player a ray cast hits. Then I damage that player, and run that exact ray cast, whilst excluding that damaged player. I would just repeat this 6 times over, i.e it would require 6 variables, 6 set variable actions, and 6 damage player actions. I am wondering if there is a more effecient way to do this, or if this would even work at all?

Edit: the above idea didn’t work

Edit: The above idea did work actually with some tweaking, and it’s pretty compact. Here’s the script on paste bin: https://pastebin.com/wrWcgFWi

Basically just set the ray cast hit player to a variable, set the next player to a variable using the same ray cast and excluding the last one, and then the next player to a variable with the same ray cast excluding the last 2 players, etc etc.

1 Like

You could ray cast hit player the first player, then ray cast hit position as the next starting point for a second ray cast hit player, etc. Repeat until ray cast hit player is null.

You could also do some math and check the distance between the orthogonal projection of the target player on the facing direction of the event player and the position of the target player. Basically that would be creating a beam with a hitbox. Unfortunately I don’t have a code example for it (yet), as I did not use it yet in any of my modes and only thought about how to do it.

You can check afterwards if any player is within a specific radius or at a specific distance towards the ray cast destination point, and if true that player or players get the damage.

I think if I try and use the hit position at the starting point for another ray cast it will just immediately collide with the first player again. I have no clue what an orthogonal projection is, but if it’s basically a beam with a hitbox i’d be happy to hear more.

Edit: I actually got it working with my idea for once, here’s the full script: https://pastebin.com/wrWcgFWi

1 Like