- Home /
[Photon]Player vs. Player Collision
I have a set-up where I have created a prefab that spawns when a player connects to the game.
attached to the prefab are child objects one is labeled as "Sword".
I'm curious how to go about the client's prefab receiving a "hit" from another prefab's child object "Sword".
the big snag is, the client1 player should only receive damage if client2 is meeting the statement of
if(Input.GetKeyDown(KeyCode.R)){
};
This is very basic for unity networking, I would recommend you to read up on the $$anonymous$$anual. Especially RPC Details, which is functions that can be called on remote machines. They can be used to send your hit message when the sword is used.
I have quite a few RPC usages in my other scripts... i'm just a bit sketchy on 'em. This is my current script which doesn't appear to do anything. Compiles nicely
using UnityEngine;
using System.Collections;
public class PVP : $$anonymous$$onoBehaviour {
public GameObject sword;
private PhotonView myPhotonView;
public GameObject health;
// Use this for initialization
void Start () {
myPhotonView = PhotonView.Get(this);
}
// Update is called once per frame
void Update () {
//if(Input.Get$$anonymous$$ey($$anonymous$$eyCode.R))//attack
myPhotonView.RPC ("OnCollisionUpdate", PhotonTargets.Others, sword, health);
}
[RPC]
void OnCollisionUpdate(Collider sword, GameObject health){
//Debug.Log (oppt.name);
health.transform.Translate(2.0f, 0.6000001f, 0.5f);
}
}
health is the green HP bar above the player's head, sword is the sword model on the prefab.
Photon? You should probably put that at least in the tags and maybe in the title, because otherwise people are going to assume you are working with the built in NetworkView.
But yeah, that does indeed look sketchy. What does "OnCollisionUpdate" even mean? Why are you using a gameobject's position for health, ins$$anonymous$$d of an int? Why are you moving it diagonally? "sword" is first declared as a GameObject, then later as a Collider. And there's no actual collision detection going on anywhere.
exactly! thank you!
I've been digging up collision articles all night and I haven't seen any collision happening, only the "OnCollisionUpdate" and "OnCollisionEnter"
I declare health as gameobject because its a visual health bar. The size should decrease to a 2.0f/x.
I can't seem to find a scale factor inside of transform or health. That makes sense why the bar was flying around at one point...
This is my first collision detection opportunity... as it has taken around 4 months to get a player of my own choice and weapons equipped, along with sending RPC's to display differences between players.
I really hope someone can at least point me in the direction of a beneficial collision article.
Scenario: 1 prefabs spawned when each client connects to the server
each client should be checking to see if another player's sword has collided with their character controller?
what type of colliders should be used? Player-tagged? Static?