Topic: [Tutorial] Mirror Particles

If you have particles that require mirroring when on 2P side, here's how to do it.

Because particle game objects themselves might not behave right when you try to rotate them, it's recommended your particle prefab has the parent most game object as an empty (put your particle inside an empty, basically).  Have the particle child rotated as if triggered from 1P side and it should work fine.

Open MoveSetScript.cs, and inside:

public class ParticleInfo:ICloneable {

add:

public bool mirrorOn2PSide;

------

Then in ControlsScript.cs, look for:

// Check Particle Effects
        foreach (MoveParticleEffect particleEffect in move.particleEffects){

and inside this after the line where pTemp is declared, add:

                    if (particleEffect.particleEffect.mirrorOn2PSide && mirror > 0) {
                        pTemp.transform.localEulerAngles = new Vector3(pTemp.transform.localEulerAngles.x, pTemp.transform.localEulerAngles.y + 180, pTemp.transform.localEulerAngles.z);
                    }

*NOTE* If you have also added the XWeaponTrail mod, you should put this into the else half of the if statement (if (particleEffect.particleEffect.isWeaponTrail) {), just after the pTemp = Instantiate() bit.
------

Finally in MoveEditorWindow.cs, look for:

moveInfo.particleEffects[i].particleEffect.prefab = (GameObject) EditorGUILayout.ObjectField("Particle Effect:", moveInfo.particleEffects[i].particleEffect.prefab, typeof(UnityEngine.GameObject), true);

and above, add:

moveInfo.particleEffects[i].particleEffect.mirrorOn2PSide = EditorGUILayout.Toggle("Mirror on Right Side:", moveInfo.particleEffects[i].particleEffect.mirrorOn2PSide, toggleStyle);

*NOTE* If you have also added the XWeaponTrail mod, you should put this into the else half of the statement, literally just after:

} else {

Share

Thumbs up +2 Thumbs down

Re: [Tutorial] Mirror Particles

I just checked the code and instructions you posted and Unity3D sent me error messages about the pTemp Variable, so after some tries just figured out the code goes inside the first 'if' in the loop you just mentioned. It Worked, I put the code exactly as it worked for me.

if (
                !particleEffect.casted && 
                particleEffect.particleEffect.prefab != null &&
                move.currentFrame >=  particleEffect.castingFrame
                ){
                particleEffect.casted = true;
                GameObject pTemp = (GameObject) Instantiate(particleEffect.particleEffect.prefab);
                
                Vector3 newPosition = myHitBoxesScript.GetPosition(particleEffect.particleEffect.bodyPart);
                newPosition.x += particleEffect.particleEffect.offSet.x * -mirror;
                newPosition.y += particleEffect.particleEffect.offSet.y;
                newPosition.z += particleEffect.particleEffect.offSet.z;

                if (particleEffect.particleEffect.mirrorOn2PSide && mirror > 0) {
                    
                    pTemp.transform.localEulerAngles = new Vector3(pTemp.transform.localEulerAngles.x, pTemp.transform.localEulerAngles.y + 180, pTemp.transform.localEulerAngles.z);
                }

                pTemp.transform.position = newPosition;
                if (particleEffect.particleEffect.stick) pTemp.transform.parent = myHitBoxesScript.GetTransform(particleEffect.particleEffect.bodyPart);
                
                Destroy(pTemp, particleEffect.particleEffect.duration);
            }

Thanks very much fot the solution

Me encontraste en un negro camino como un peregrino sin rumbo ni fe, pero la luz de tus ojos divinos cambió mi suerte por dicha y placer.

Re: [Tutorial] Mirror Particles

XWeaponTrail adds another if statement inside that one.  I've corrected my original post to reflect that now too smile.

Share

Thumbs up +2 Thumbs down

Re: [Tutorial] Mirror Particles

Works perfect Now! THanks!

http://s5.postimg.org/gif520gvr/mirror_ufe.jpg

Me encontraste en un negro camino como un peregrino sin rumbo ni fe, pero la luz de tus ojos divinos cambió mi suerte por dicha y placer.

Re: [Tutorial] Mirror Particles

can we mirror projectile as well??

Share

Thumbs up Thumbs down

Re: [Tutorial] Mirror Particles

There is another problem:
As mentioned above,it only rotate the particle not really mirror.

Share

Thumbs up Thumbs down

Re: [Tutorial] Mirror Particles

knightgabriel4eva wrote:

can we mirror projectile as well??

To mirror projectiles, you'll just need to apply the same principle of rotating the transform when you instantiate it.  Have a look at the Projectile creation parts of the code and you should be able to work it out.

GameFinderToday wrote:

There is another problem:
As mentioned above,it only rotate the particle not really mirror.

This system assume you're using 3D particles, so rotating them 180 in y axis will work.  If you're using 2D sprite particles, then you'll want to multiple x axis by -1 instead of rotating y by 180.

If your game has both 3D and 2D particles, I would suggest creating another bool to check for 2D particle to mirror.

Share

Thumbs up +1 Thumbs down

Re: [Tutorial] Mirror Particles

i cant seem to fig out how to mirror projectile..
not even sure where to look for.,...

Share

Thumbs up Thumbs down

Re: [Tutorial] Mirror Particles

Is there a way to mirror Particles used on On Hit effects ?

Share

Thumbs up Thumbs down

Re: [Tutorial] Mirror Particles

knightgabriel4eva wrote:

i cant seem to fig out how to mirror projectile..
not even sure where to look for.,...

ControlsScript.cs, look for where the Projectile Options are applied.  It's basically the same principle, but you might also need to use ProjectileMoveScript.cs for the actual projectile.

hollysephiroth wrote:

Is there a way to mirror Particles used on On Hit effects ?

Yep, definitely possible.  You just need to apply the same changes to the Hit Effects options in Global config, and maybe also in your Override Hit Effects options in Move files.

Share

Thumbs up Thumbs down

Re: [Tutorial] Mirror Particles

Woow, This solution is awesome.

It's works very fine. I really like this solution.

Thank you so much YumChaGames.

I also want to special thank you to StriderSpinel , because it's solution with Image will also very much helpful to me.

Thank you both.

Share

Thumbs up Thumbs down

12 (edited by knightgabriel4eva 2015-10-16 04:26:47)

Re: [Tutorial] Mirror Particles

I have been trying to mirror projectile
but I keep I failing.... I am getting error

I get this error message

Assets/UFE/Scripts/ControlsScript.cs(1000,65): error CS1061: Type `UnityEngine.GameObject' does not contain a definition for `mirrorOn2PSide' and no extension method `mirrorOn2PSide' of type `UnityEngine.GameObject' could be found (are you missing a using directive or an assembly reference?)


has anyone figured it out?

Share

Thumbs up Thumbs down

13 (edited by SudhirKotila 2015-10-16 04:35:08)

Re: [Tutorial] Mirror Particles

knightgabriel4eva wrote:

I have been trying to mirror projectile
but I keep I failing.... I am getting error

I get this error message

Assets/UFE/Scripts/ControlsScript.cs(1000,65): error CS1061: Type `UnityEngine.GameObject' does not contain a definition for `mirrorOn2PSide' and no extension method `mirrorOn2PSide' of type `UnityEngine.GameObject' could be found (are you missing a using directive or an assembly reference?)


has anyone figured it out?


Follow the post of YumChaGames post no:1

its out put you can viewed in post no : 2

So Please compare your script with post no : 2

I was just follow all the instruction it is working successfully.

Share

Thumbs up Thumbs down

Re: [Tutorial] Mirror Particles

I mirror particle but I coudnt mirror projectile..
I maybe doing something wrong
I think I have to add 'mirrorOn2PSide' somewhere in projectilemoveset.. but I coudnt fig that out..

Share

Thumbs up Thumbs down

Re: [Tutorial] Mirror Particles

knightgabriel4eva wrote:

I mirror particle but I coudnt mirror projectile..
I maybe doing something wrong
I think I have to add 'mirrorOn2PSide' somewhere in projectilemoveset.. but I coudnt fig that out..


you have to write code of editor for checkbox in projectile.

you can refer post no : 1 by YumChaGames.

Look at script of "MoveEditorWindow".

Share

Thumbs up Thumbs down

Re: [Tutorial] Mirror Particles

I still cant do it... hopeless...have to find some way to go around use actual particle emitter or something like that..

Share

Thumbs up Thumbs down

Re: [Tutorial] Mirror Particles

Was able to add similar code for a projectile mirror, but sadly it doesn't seem to work. It won't mirror it when created.

1. Added the following to MoveInfo.cs

public class Projectile: ICloneable {
...
public bool mirrorOn2PSide;
...
}

2. Added the following to ControlsScript.cs

// Check Projectiles
...
GameObject pTemp = (GameObject) Instantiate(
                    projectile.projectilePrefab, 
                    newPos, 
                    Quaternion.Euler(0,0,projectile.directionAngle)
                    );

if (projectile.mirrorOn2PSide && mirror > 0) {
     pTemp.transform.localEulerAngles = new Vector3(pTemp.transform.localEulerAngles.x, pTemp.transform.localEulerAngles.y + 180, pTemp.transform.localEulerAngles.z);
}
...

3. Added the following to MoveEditorWindow.cs

...
EditorGUILayout.Space();
moveInfo.projectiles[i].mirrorOn2PSide = EditorGUILayout.Toggle("Mirror on Right Side:", moveInfo.projectiles[i].mirrorOn2PSide, toggleStyle);
moveInfo.projectiles[i].projectilePrefab = (GameObject) EditorGUILayout.ObjectField("Projectile Prefab:", moveInfo.projectiles[i].projectilePrefab, typeof(UnityEngine.GameObject), true);
...
                                

4. Took my Projectile particle effect and set it as a child under an empty GameObject.

5. Marked the move to Mirror on 2P side.

6. Booted game, to see mirroring wasn't occuring for the projectile. Also when debugging, changing the Y rotation of the empty gameobject will not rotate the particle effect projectile.

Share

Thumbs up Thumbs down

18 (edited by MrPonton 2016-07-25 15:12:39)

Re: [Tutorial] Mirror Particles

Was able to get some progress in on this, still have a bug where it looks like the X size of the particle seems is not correct, but it's at least facing the right way. Also, this does not require you to put the particle effect under an empty GameObject.

In ControlsScript.cs after pTemp gets instantiated.

// Mirror if firing on P2 side
if (projectile.mirrorOn2PSide && mirror > 0) {
    ParticleSystem psys = pTemp.GetComponentInChildren<ParticleSystem>();
    psys.startRotation3D = new Vector3(psys.startRotation3D.x, psys.startRotation3D.y + 180, psys.startRotation3D.z);
}

Share

Thumbs up Thumbs down

Re: [Tutorial] Mirror Particles

so how do i apply this to unity 5.4??
i tried but somehow it works only on one character of mine but doesnt work on the other characters..
so weird...

Share

Thumbs up Thumbs down

20 (edited by KRGraphics 2016-10-13 10:28:40)

Re: [Tutorial] Mirror Particles

Just seeing this thread... and being as I don't have UFE Source, I can't edit the script. I am surprised that it didn't make it into the latest update. Also what if I want different colour particles for another character... could I also apply the particle prefab to the movelist of the character instead?