Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
avatar image
0
Question by sozeray · Aug 24, 2013 at 10:58 PM · collisionparticlescollision detectiondetectionparticle collision

Detecting collision between particle and player.

Hello,

I am trying to make my game detect the collision between pepper gas smoke particles and my player, and if such collision occurs, apply some damage to the player. But as I have spent my last 2 days, although I can see the collision happening in the game scene, the collision has never been detected. I use Shuriken particle system. I checked the collision in the inspector, and both the player and the particle system has the RigidBody physic.

My code goes as:

 #pragma strict
 
 var P : GameObject;
 var HitByGaz : boolean = false;
 
 function OnParticleCollision (other : GameObject) {
 
             Debug.Log ("Pepper gas!");
 
             
             if(other.tag == "Player") {
             
             P.gameObject.GetComponent(PlayerHealth).currentHealth -= 1;
             HitByGaz = true;
             HitByGaz = false;
         
         
     }
 }

I can't even get the log working. Thanks for helping out.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Hasi_Indie · Dec 25, 2013 at 05:30 PM

 #pragma strict
 var player : GameObject;
    
     function OnParticleCollision (other : GameObject) {
         var body : Rigidbody = other.rigidbody;
         if (body) {
             Debug.Log("player");
         }
     }

works for me... if not working set your collision quality to high.

Comment
Add comment · Share
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
avatar image
0

Answer by AD110 · Jan 17, 2017 at 02:22 PM

using UnityEngine;

using System.Collections;

using System.Collections.Generic;

public class Example : MonoBehaviour

{

 public ParticleSystem.Particle[] ParticleList;

 private ParticleSystem m_particleSystem;

 private GameObject character;

 int Score = 0;

 void Start()
 {
     character = GameObject.FindGameObjectWithTag ("Iz");

     m_particleSystem = GetComponent<ParticleSystem> ();
 }

 void LateUpdate ()
 {
     //This list will be used to store each particle that is alive 

     ParticleList = new ParticleSystem.Particle[m_particleSystem.particleCount];

     //storing particles into a list
     m_particleSystem.GetParticles (ParticleList);

     // Change only the particles that are alive
     for (int z = 0; z < GetComponent<ParticleSystem> ().particleCount; z++) 
     {    
         //getting the position of the player and the particle
         Vector3 dis = ParticleList [z].position - character.transform.position;

         //if it is near
         if(dis.magnitude <= 5)
         {
             //destroy the particle
             ParticleList [z].lifetime = 0;
             //add score
             Score++;
         }
     }

     // Apply the particle changes to the particle system
     m_particleSystem.SetParticles (ParticleList, m_particleSystem.particleCount);
 }

}

Comment
Add comment · Share
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

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

17 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

Related Questions

Inconsistent Particle Collision detection 0 Answers

Particle Collision / Trigger not being reported to On_xx Event 1 Answer

Whirlwind spell collision detection 1 Answer

Let Particles sit on Collider without triggering callback - OnParticleCollisionEnter? . 1 Answer

Particle collision problem 0 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