Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by marpione · Jun 21, 2017 at 09:37 PM · unity 5networkingparticlesparticlesystemparticle collision

particle collision events networking

Hello, I'm trying make a multiplayer game with particle collisions. It's an FPS game Using a gun that emits particles and when they collide it emits other particles at the collision location. I followed the Unity particle scripting tutorials to create the core mechanics of the game and my code it pretty much identical. See the link below for the tutorial. I'm using Unet for networking and at the moment I can emit particles for each client but collision is not working. I check the components and when I remove networking code collision works. I can't pass Client RPC or comment to methods that have Particle Collision Events. Particles are not colliding even locally. You can see the code down below.

All I want to do is to collide particle trough network. Everyone will be able to see the particles when they get collided. Also damage other players with particle collisions but I think I can solve that once I understand how I can pass particles through network.

Thanks in advance for the help.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.Networking;
 
 public class ParticleLuncher : NetworkBehaviour {
 
     ParticleSystem system;
     public ParticleSystem splatterParticles;
     public Gradient particleColor;
     public ParticleDecalPool decalPool;
 
     List<ParticleCollisionEvent> collisionEvents;
 
     // Use this for initialization
     void Start () {
 
         if (!isLocalPlayer)
             this.enabled = false;
 
         system = GetComponentInChildren<ParticleSystem>();
         collisionEvents = new List<ParticleCollisionEvent>();
         splatterParticles = FindObjectOfType<SplatOnCollision>().GetComponent<ParticleSystem>();
         decalPool = FindObjectOfType<ParticleDecalPool>();
     }
 
 
     void OnParticleCollision(GameObject other)
     {
 
         ParticlePhysicsExtensions.GetCollisionEvents(system, other, collisionEvents);
 
         for (int i = 0; i < collisionEvents.Count; i++)
         {
             decalPool.ParticleHit(collisionEvents[i], particleColor);
             EmitAtLocation(collisionEvents[i]);
         }
 
 
         if (!isServer)
             return;
 
         //Find Player Health do the damage.
     }
         
     
     void EmitAtLocation(ParticleCollisionEvent PCE)
     {
         splatterParticles.transform.position = PCE.intersection;
         splatterParticles.transform.rotation = Quaternion.LookRotation(PCE.normal);
         ParticleSystem.MainModule psMain = splatterParticles.main;
         psMain.startColor = particleColor.Evaluate(Random.Range(0f, 1f));
         splatterParticles.Emit(1);
     }
     
     // Update is called once per frame
     void Update () {
 
         if (!isLocalPlayer)
             return;
 
         if (Input.GetButton("Fire1"))
         {
             ParticleSystem.MainModule psMain = system.main;
             psMain.startColor = particleColor.Evaluate(Random.Range(0f, 1f));
             system.Emit(1);
         }   
     }
 }
 

Particle Pool Script

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.Networking;
 
 public class ParticleDecalPool : NetworkBehaviour {
 
     private int particleDataIndex;
     public int maxDecal = 1000;
     private ParticleDecalData[] particleData;
     public float DecalSizeMin = 0.5f;
     public float DecalSizeMax = 1.5f;
     public ParticleSystem.Particle[] particles;
     private ParticleSystem decalParticleSystem;
 
 
     // Use this for initialization
     void Start () {
 
         particleData = new ParticleDecalData[maxDecal];
         particles = new ParticleSystem.Particle[maxDecal];
         decalParticleSystem = GetComponent<ParticleSystem>();
 
         for (int i = 0; i < maxDecal; i++)
         {
             particleData[i] = new ParticleDecalData();
         }
     }
     
     
     public void ParticleHit(ParticleCollisionEvent PCE, Gradient colorGradient)
     {
 
         SetParticleData(PCE, colorGradient);
         DisplayParticle();
     }
 
 
     void SetParticleData(ParticleCollisionEvent PCE, Gradient colorGradient)
     {
         if (particleDataIndex >= maxDecal)
         {
             particleDataIndex = 0;
         }
 
         //Record Collision pos, rot, size, color
 
         particleData[particleDataIndex].pos = PCE.intersection;
         Vector3 particleRotEuler = Quaternion.LookRotation(PCE.normal).eulerAngles;
         particleRotEuler.z = Random.Range(0, 360);
         particleData[particleDataIndex].rot = particleRotEuler;
         particleData[particleDataIndex].size = Random.Range(DecalSizeMin, DecalSizeMax);
         particleData[particleDataIndex].color = colorGradient.Evaluate(Random.Range(0f, 1f));
 
 
         particleDataIndex++;
     }
     void DisplayParticle()
     {
 
         for (int i = 0; i < particleData.Length; i++)
         {
             particles[i].position = particleData[i].pos;
             particles[i].rotation3D = particleData[i].rot;
             particles[i].startSize = particleData[i].size;
             particles[i].startColor = particleData[i].color;
         }
 
         decalParticleSystem.SetParticles(particles, particles.Length);
     }
 }
 

Script that emits splashes.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.Networking;
 
 public class SplatOnCollision : NetworkBehaviour {
 
     public ParticleSystem particleLauncher;
     public Gradient particleColorGradient;
     public ParticleDecalPool dropletDecalPool;
 
     List<ParticleCollisionEvent> collisionEvents;
 
 
     void Start () 
     {
         collisionEvents = new List<ParticleCollisionEvent> ();
     }
 
 
     
     void OnParticleCollision(GameObject other)
     {
 
         int numCollisionEvents = ParticlePhysicsExtensions.GetCollisionEvents (particleLauncher, other, collisionEvents);
 
         int i = 0;
         while (i < numCollisionEvents) 
         {
                dropletDecalPool.ParticleHit(collisionEvents[i], particleColorGradient);
             i++;
         }
 
     }
 
 }
 



Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

193 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Emit Particles in 45 degree steps ? 1 Answer

How do i spawn particles over network for everyone too see in UNET? 1 Answer

Particles don't bounce in game, but do in editor 0 Answers

How to sync particles over UNet 0 Answers

Particles syncing on the Unity Network 4 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges