Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 MadMapp · Dec 10, 2013 at 12:24 PM · particlecollisions

Particle collisions for a NOOB??

hi all, using unity for a while now but have never done collisions with particles, im not sure what im doing wrong/or right,

so i have a player running around with a flamethrower, this is made from a particle systems component, when i hit the enemy with the particle i want it do damage,

i have this code on my object that has the particle emmiter

public var damage = 40;

function OnParticleCollision (collision: GameObject ) { if(collision.transform.tag == "Enemy") {

 Debug.Log("Damage"); 
 collision.GetComponent(ZombieStats).Hit(damage);
 } 

}

and this code is on my enemies

 var health : float;
 var deathFX : GameObject;
 
 public var hitFX : GameObject;            //Hit FX
 
 function Start () {
 
 }
 
 function Update () {
 
     if (health <= 0){
     Instantiate(deathFX,transform.position,Quaternion.identity);
         Destroy (this.gameObject);
     }
 
 }
 
 public function Hit(_damage : int)
 {
     //Instantiate hit FX
     Instantiate(hitFX,transform.position,Quaternion.identity);
     //Remove the damage value from the health
     health -= _damage;
     //If health is less than 0
 
 }


i have the collisions box ticked, its set to world, and send collision messages is also ticked

im sure this is really easy fix for some1, but im all confused, any help or a point in the right direction is appreciated

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

1 Reply

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

Answer by GameVortex · Dec 10, 2013 at 12:37 PM

It is not the collision that contains the component ZombieStats but the gameobject inside the collision. You can use collision.gameObject to access the GameObject the particle collided with.

 public var damage = 40;
 
 function OnParticleCollision (collision: GameObject ) { if(collision.transform.tag == "Enemy") {
     Debug.Log("Damage"); 
     collision.gameObject.GetComponent(ZombieStats).Hit(damage);
 } 

Also for future reference, please properly describe what your problem with the code is and post any errors you might be getting (also include the line number).

Comment
Add comment · Show 2 · 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 MadMapp · Dec 11, 2013 at 09:51 AM 0
Share

hi Vortex,

for some reason its not letting me post as a comment, so i had to put this in as an answer

thanks for the reply, correct me if im wrong , i thought function OnParticleCollision( collision(name the collision for refrence):GameObject(system type)

so when i get to collision.GetComponent... collision had already been declared as a GameObject,

im still having issues, i change the code to yours, no errors in console, none at run time,

im not getting a debug to say ive hit,

i changed the renderer setting from billboard to mesh.. thinking that would solve it but not such luck

avatar image GameVortex · Feb 13, 2014 at 07:27 PM 0
Share

Hi, I am sorry I did not see your comment before. You are absolutely right, I was thinking about OnCollisionEnter which takes a parameter of type Collision. The onparticlecollision is of course already a GameObject. You have probably figured out by now what the problem is, but just for any other that might see this: the issue comes from the fact that it is the receiving GameObject that needs a script with the onparticlecollision callback and not the particle emitter itself.

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

Different particles for different collisions. 1 Answer

Particle rotation: supported yet? 1 Answer

Particle emitter to emit "one-shot" on specific occasions 5 Answers

Particle GameObject refuses to drag into Prefab? 1 Answer

Instantiated object won't collide with particles 1 Answer


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