playMaker

Author Topic: Shuriken Particle Collisions: Get Source of Particles?  (Read 3365 times)

jameskyle

  • Playmaker Newbie
  • *
  • Posts: 15
Shuriken Particle Collisions: Get Source of Particles?
« on: August 01, 2014, 07:57:15 AM »
I'm working on a simple shmup-style game and handling player and enemy projectiles using the Shuriken particle system. I have things almost working but to properly remove the correct amount of damage I'd need to know something about the source of the particle . Is there any way to do this?

I've been using https://hutonggames.fogbugz.com/default.asp?W1141 as the starting point for my work with particle collisions and I see that point 5 of scene set-up may be what I'm looking for but I'm not sure how to achieve what it's referring to.

Palanysamy

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Shuriken Particle Collisions: Get Source of Particles?
« Reply #1 on: August 01, 2014, 08:23:18 AM »
Do a compare with the particle system name and trigger events based on it.

jameskyle

  • Playmaker Newbie
  • *
  • Posts: 15
Re: Shuriken Particle Collisions: Get Source of Particles?
« Reply #2 on: August 01, 2014, 09:12:19 AM »
I hope this isn't really obvious and I just can't see it but I'm having trouble getting the particle system name. Actions like Get Name or String Switch ask for game object references or variables and I'm not sure how to pass them the particle system that's triggered the by On Particle Collision.

I've based my FMS on the one in the demo scene from the Shuriken Addon page linked in the first post. The FSM is applied to a child of my enemy game object (the enemy game object has a 2D collider already attached, as the game is mostly 2D.) It's laid out as in the attached image. This is all probably not relevant to finding a solution but I thought I'd share it just in case.

jameskyle

  • Playmaker Newbie
  • *
  • Posts: 15
Re: Shuriken Particle Collisions: Get Source of Particles?
« Reply #3 on: August 01, 2014, 11:51:36 AM »
Being unable to find a Playmaker-only solution I decided to use a script.

Code: [Select]
using UnityEngine;
using System.Collections;

public class getParticleCollisionSource : MonoBehaviour {

public GameObject particleSource;
public int numCollisionEvents;
private ParticleSystem.CollisionEvent[] collisionEvents = new ParticleSystem.CollisionEvent[16];

// Use this for initialization
void Start ()
{

}

// Update is called once per frame
void Update ()
{

}

void OnParticleCollision(GameObject other) {
particleSource = other;
// ParticleSystem particleSystem;
// particleSystem = other.GetComponent<ParticleSystem>();
numCollisionEvents = particleSystem.GetCollisionEvents(gameObject, collisionEvents);
}
}
With the Get Property action I can access the GameObject variable in the script (see attachment) and use that in switches as needed. It's not an ideal solution but the result is the same.

(Also, some links to relevant reference info I used to figure this all out for those finding this thread in the future:
http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnParticleCollision.html
http://hutonggames.com/playmakerforum/index.php?topic=4612.0)

Palanysamy

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Shuriken Particle Collisions: Get Source of Particles?
« Reply #4 on: August 01, 2014, 02:52:32 PM »
yeah I did it with a script as well, seems you got much more control with it.