- Home /
Unet Rigidbody Bullet Collisions
Hello, I am making a unet game in which players shoot projectiles at each other that are slow enough that it can detect ontrigger collisions. I have a pretty good script written out that used to work fine, but does not work anymore, not sure how it changed but it did. So I am turning to the community to try to get my scripts in working order. Basically on the player there is a shoot script that spawns a bullet prefab on the server and then gives that spawned bullet the gameobject that spawned in that bullet and how much damage it does based off the player's stats. Then if the bullet collides with another player, it will damage that player. As of now whoever is the server can only damage the clients, while the clients cannot damage the server client. Any suggestions would be awesome thanks!
// Shoot function attached to the player
void LeftClick () {
var _mainSpell = Instantiate (fireballSpell, projectileSpwan.transform.position, projectileSpwan.transform.rotation);
CmdLeftClickEffect (_mainSpell);
canFireBall = false;
FireBallCoolDownTime = 0f;
fireBallIcon.fillAmount = 0f;
shotFireBall = true;
}
[Command]
void CmdLeftClickEffect (GameObject _mainSpell) {
string thisPlayersID = gameObject.GetComponent<playerSetup> ().IDTag;
float _damage = this.gameObject.GetComponent<playerStats> ().DetermineDamageFireBall ();
_mainSpell.GetComponent<splashDamage>().setCastersId (thisPlayersID, _damage);
NetworkServer.Spawn (_mainSpell);
}
// The script attached to the projectile
public void setCastersId (string _playerID, float _damage) {
ID = _playerID;
damage = _damage;
}
public void nullPlayer () {
playerWeHit = null;
}
void OnTriggerEnter (Collider col) {
if (col.gameObject.name != ID && col.gameObject.tag == "Player") {
playerWeHit = col.gameObject;
Debug.Log ("hit " + playerWeHit.name);
RpcTakeDamage (playerWeHit, damage);
Invoke ("nullPlayer", 1f);
}
}
[Command]
void RpcTakeDamage (GameObject _player, float _dammageAmount) {
_player.gameObject.GetComponent<playerStats> ().RpcTakeDamage (_dammageAmount);
}
// The player stats function that takes damage
[ClientRpc]
public void RpcTakeDamage (float _dammage) {
_dammage = _dammage * armorMultiplier;
currentHealth -= _dammage;
Die ();
}
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
Custom network ID values 0 Answers
Network View ID Allocation 1 Answer
Best way to choose Google Play Realtime Multiplayer Host? 0 Answers