Bullet damage to other player with raycasting. Answer fast please(
The whole answer can be found below.
Try Our
Documentation
Please check if you can find an answer in our extensive documentation on PUN.
Join Us
on Discord
Meet and talk to our staff and the entire Photon-Community via Discord.
Read More on
Stack Overflow
Find more information on Stack Overflow (for Circle members only).
Bullet damage to other player with raycasting. Answer fast please(
twonkykong
2020-10-28 08:48:25
So, I made a gun with raycasting and I don't know how to apply damage to player I'm looking at. Just like: if (Physics.Raycast(...)) { if (hit.collider.tag == "Player") hit.collider.GetComponent
But how to do it over PUN2?
Comments
Sending an RPC. If you don't know what this is check out https://doc.photonengine.com/en-us/pun/v2/demos-and-tutorials/pun-basics-tutorial/intro.
twonkykong
2020-10-29 07:21:07
@S_Oliver wrote: »
Sending an RPC.
ye i already got it.
For thoose who went here for help:
void Update()
{
RaycastHit hit;
if (Physics.Raycast(head.transform.position, transform.forward, out hit, 50f))
{
if (hit.collider.tag == "Player")
{
this.photonView.RPC("GetDamage", RpcTarget.All, hit.collider.GetComponent
}
}
}
[PunRPC]
public void GetDamage(string userid)
{
if (PhotonNetwork.LocalPlayer.Owner.UserID == userid)
{
GetComponent
}
}
i think i wrote something wrong but the main idea is that we have method which we give a player's user id that we looking at
then the method on all players' clients checks, if one of player has the same userid as given one
if true: get damaged
hope you understand, it is so simple for me. I was thinking about it 1 day
Back to top