hey ![]()
i want to make that if i’m throwing a grenade , when he explode, and my friend (enemy) is in the radius, he will ge damage.
how can i do that?
UP.
In the client have a function of grenade that you initiate from the server, then just check if friend.position is within a distance of grenade.position
I would use Physics.OverlapSphere, with the grenade being the center of the sphere, which will get you a list of all objects in a certain distance of the grenade. Then you check for players in that list. But just because they are in that list doesn’t mean the grenade should hit them because they might be behind cover. So after getting that list you could use Physics.SphereCast, starting from the grenade and ending at the player’s position, to check if there are any obstacles on the path toward the player, and only damage them if there isn’t
You could do this one of three ways…
-
On the client side (throwers)
— Determine if ANY players are within the damage radius, if they are, send a signal to the server, which then tells the players that they should be damaged. -
On the client side (victims)
— Determine if you are within the damage radius, if you are, take the damage. -
On the server side
— Determine if ANY players are within the damage radius, if they are, send a signal to the player, which tells them that they should be damaged.
On the throwers side, this could be exploited, as a simple grenades radius could be expanded through mods/hacks.
On the victims side, this could be exploited, as a simple grenade radius could be lowered through mods/hacks.
On the server side, this would add more processing/calculation therefore making the server run less efficiently.