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
1
Question by oliver-jones · Apr 03, 2011 at 05:49 PM · particlemessagesendreceiveflamethrower

Flame Thrower - Particle Collision Help

Hello,

I'm working on a flame thrower turret, and I basically have two main scripts attached to the turret, and a damage receiver script attached to the enemy.

One of the scripts on the turret (SmoothLookAt), controls the rotation of the turret when an enemy walks into range.

The other one (FlameController), controls the particle emitter (the flame) and sends the damage to the damage receiver attached to the enemy - which is what I am having a problem with.

I want to follow the FPS tutorial (unity) closely (as my other turrets use the same format), I want to be able to do something like this:

something.SendMessageUpwards("ApplyDamage", flameDamage, SendMessageOptions.DontRequireReceiver);

So I want FlameController to receive if the particles have hit any game objects (enemy), and if so - send the damage to the receiver on the enemy.

I've looked at function OnParticleCollision - but thats a receiver, which means I'll have to place it in my DamageReciever, right?

Well anyway, here are my scripts:

FlameController:

private var flameDamage : float = 0.2; var flameRange : float; var flameOn : boolean = false; var flameParticle : ParticleEmitter;

 //ExternalSmooth = gameObject.GetComponentInChildren(SmoothLookAt);

function Update () {

 var ExternalSmooth : SmoothLookAt;
 ExternalSmooth = gameObject.GetComponentInChildren(SmoothLookAt);

 // controls flame particle
 if(ExternalSmooth.target){
     flameOn = true;
     flameParticle.particleEmitter.emit = true;
 }
 else{
     flameOn = false;
     flameParticle.particleEmitter.emit = false;
 }

 // somehow send damge from particle.collider.SendMessageUpwards("ApplyDamage", flameDamage, SendMessageOptions.DontRequireReceiver);

}

DamageReceiver: (from the FSP tutorial - modified slightly)

static var Health; var hitPoints = 10.0; var MaxHitPoints = 10.0; var HealthBarSize : float = 0.2; var detonationDelay = 0.0; var explosion : Transform; var deadReplacement : Rigidbody; var credits = 100; private var damageByFlames : float = 0.6;

public var Dead = false;

/* function OnParticleCollision(){ print("HIT BY FIRE!!"); //currently recieving - i do not want that - i flamecontroller to send damge report

} */

function Start(){ Health = Controller.EnemyHealth; hitPoints = Health; MaxHitPoints = Health; }

function Update(){ var script : HealthBar; script = gameObject.GetComponentInChildren(HealthBar); script.Health = hitPoints; script.MaxHealth = MaxHitPoints; script.MaxBar = HealthBarSize; }

function ApplyDamage (damage : float) { // We already have less than 0 hitpoints, maybe we got killed already? if (hitPoints <= 0.0) //credits += 100; return;

 hitPoints -= damage;
 if (hitPoints &lt;= 0.0) {
     // Start emitting particles
     var emitter : ParticleEmitter = GetComponentInChildren(ParticleEmitter);
     if (emitter)
         emitter.emit = true;

     Invoke("DelayedDetonate", detonationDelay);
 }

}

function DelayedDetonate () { //GetComponent(SmoothLookAt).LookAtDead = false; BroadcastMessage ("Detonate"); //Dead = true; }

function Detonate () { // Destroy ourselves Credits.Credits += 90; Controller.EnemyAdding ++; Destroy(gameObject);

 // Create the explosion
 if (explosion)
     Instantiate (explosion, transform.position, transform.rotation);

 // If we have a dead barrel then replace ourselves with it!
 if (deadReplacement) {
     var dead : Rigidbody = Instantiate(deadReplacement, transform.position, transform.rotation);

     // For better effect we assign the same velocity to the exploded barrel
     dead.rigidbody.velocity = rigidbody.velocity;
     dead.angularVelocity = rigidbody.angularVelocity;
 }

 // If there is a particle emitter stop emitting and detach so it doesnt get destroyed
 // right away
 var emitter : ParticleEmitter = GetComponentInChildren(ParticleEmitter);
 if (emitter) {
     emitter.emit = false;
     emitter.transform.parent = null;
 }

}

// We require the barrel to be a rigidbody, so that it can do nice physics @script RequireComponent (Rigidbody)

Sorry for the essay, but I'm trying to make my self clear. I would appreciate any help.

Thanks!

Summary:

Any way to do it like this:

OnParticleCollision.SendMessageUpwards("ApplyDamage", flameDamage, SendMessageOptions.DontRequireReceiver);
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 Statement · Apr 03, 2011 at 05:59 PM

I've looked at function OnParticleCollision - but thats a receiver, which means I'll have to place it in my DamageReciever, right?

From the docs: This message is sent to all scripts attached to the WorldParticleCollider and to the Collider that was hit.

I'd put this code in FlameController.js, given it sits on the same object as the WorldParticleCollider, or add a component with this code to the WorldParticleCollider (During Start, if it hasn't got one).

function OnParticleCollision (other : GameObject) {
    other.SendMessageUpwards("ApplyDamage", flameDamage, 
                      SendMessageOptions.DontRequireReceiver);
}

Depending on your hierarchy of objects you might want change SendMessageUpwards to SendMessage or BroadcastMessage, it's up to you.


ParticleDamage.js

var damage : float;
function OnParticleCollision (other : GameObject) {
    other.SendMessageUpwards("ApplyDamage", flameDamage, 
                      SendMessageOptions.DontRequireReceiver);
}


FlameController.js

private var flameDamage : float = 0.2; private var externalSmooth : SmoothLookAt; private var particleDamage : ParticleDamage;

var flameRange : float; var flameOn : boolean = false; var flameParticle : ParticleEmitter;

// Cache externalSmooth externalSmooth = gameObject.GetComponentInChildren(SmoothLookAt);

// Set up particleDamage: particleDamage = flameParticle.GetComponent(ParticleDamage); if (!particleDamage) particleDamage = flameParticle.gameObject.AddComponent(ParticleDamage);
particleDamage.damage = flameDamage;

function Update () { if(ExternalSmooth.target){ flameOn = true; flameParticle.emit = true; } else{ flameOn = false; flameParticle.emit = false; } }

Comment
Add comment · Show 5 · 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 oliver-jones · Apr 03, 2011 at 06:06 PM 0
Share

Not working :( - $$anonymous$$y SmoothLookAt script and FlameController are both on the same object - in the same hierarchy. Although my particle is within a child of the object that those scripts are attached to

avatar image Statement · Apr 03, 2011 at 06:08 PM 0
Share

See my updated answer. It will add a ParticleDamage script to the emitter if it doesn't have any.

avatar image oliver-jones · Apr 03, 2011 at 06:09 PM 0
Share

Because my FlameController is not on particle system - is there a way to use OnParticleCollision to read off a variable that is set as a particle? So: var paricleSystem : ParticleEmitter; then: ParticleEmitter.OnParticleCollision?

avatar image Statement · Apr 03, 2011 at 06:15 PM 0
Share

We access the particle emitter through your variable flameParticle. It sits on the gameObject that is emitting particles obviously. So what we can do then is add ParticleDamage (see my script above) to the same gameObject with AddComponent. This will handle sending ApplyDamage to any colliders it hit. So you push a script to the right location. (You could always just manually put it on the emitter object as well)

avatar image oliver-jones · Apr 03, 2011 at 06:55 PM 0
Share

I didnt want to have to create another script to put on my particle system - but hey! - Works anyway - cheers!

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

No one has followed this question yet.

Related Questions

how to send message every few seconds? 3 Answers

how do i send and receive messages in a game object? 1 Answer

Trouble sending message... 2 Answers

SendMessage every second? 2 Answers

Collision script 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