Particle rotation problems in Unity 2017.1.0f3
Hi everyone. After updating to Unity 2017.1.0f3 I have had a problem with the rotation of spawned particle systems, I am using gameObjects with particle systems and firing their rigidbodies as bullets in a game.
In the old version of unity the bullets inherit the value of the gun they are spawned from, but in updated Unity the bullets or at least their particle systems seem seem to be given the rotation of the world space. I have included the bullet firing code below.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class UniversalShooterScript : MonoBehaviour {
//Weapon Values
[SerializeField]
Rigidbody projectile;
public float speed;
[SerializeField]
float refireRate;
bool canFire;
//Effect
[SerializeField]
AudioClip[] fireSound;
AudioSource source;
[SerializeField] ParticleSystem onShot;
public int emitAmount;
//Energy Drain
public PowerCapacity power;
[SerializeField] float energyDrain;
//Hangar Values
public string weaponName;
public string weaponType;
public GameObject descText;
GameObject inHangar;
public void Start()
{
canFire = true;
StartCoroutine(getPower());
StartCoroutine(seeIfHangarTrue());
}
IEnumerator seeIfHangarTrue()
{
inHangar = GameObject.Find("HangarManager").gameObject;
yield return new WaitForEndOfFrame();
if (inHangar != null)
{
canFire = false;
}
else if(inHangar == null)
{
canFire = true;
}
yield return new WaitForSeconds(2f);
StartCoroutine(seeIfHangarTrue());
}
IEnumerator getPower()
{
yield return new WaitForEndOfFrame();
power = GameObject.FindWithTag("Player").GetComponent<PowerCapacity>();
}
void Update () {
if (Input.GetMouseButton(1) && (canFire) && (power.currentCapacity >= energyDrain)) {
StartCoroutine("Shoot");
power.currentCapacity -= energyDrain;
}
}
IEnumerator Shoot() {
{
StartCoroutine(playParticle());
Rigidbody instantiatedProjectile = Instantiate(projectile,transform.position,transform.rotation)
as Rigidbody;
instantiatedProjectile.velocity = transform.TransformDirection(new Vector3(0,0,speed));
{
canFire = false;
yield return new WaitForSeconds(refireRate);
canFire = true;
}
}
}
IEnumerator playParticle ()
{
onShot.Emit(emitAmount);
yield return new WaitForEndOfFrame();
}
}
These gifs show the problem in the first gif bullets face forward from their firing point... Before. [img]https://i.imgur.com/k3Z2w7V.gif[/img] ...Where as in the second gif the bullets fly facing the same direction all the time even no matter the rotation of the gun. After. [img]https://i.imgur.com/aR7sw1s.gif[/img]
Any help would be greatly appreciated, thank you.
Found a soloution. In the particle system in the inspector, there is a new section in the emissions panel with position, rotation and scale options. When I changed the scale option from 0 to 0.01 the problem was solved. I don't know how or why that fixed it but it did.
Answer by ifurkend · Oct 12, 2017 at 12:09 AM
Try changing the velocity mode or something like that in the main module which allows you switching between "rigidbody" and "transform".
Digression: 2017.1p3 particle system has a performance issue which is fixed from 2017.1p4.
Answer by Omerl_ahire · Oct 12, 2017 at 12:54 AM
@ifurkend Thanks for your reply. I have already tried the velocity mode and unfortunately there was no change, I also changed the render alignment to velocity but that made the bullets faded looking and didn't effect rotation.
$$anonymous$$aybe I'll just update unity and hope that solves the problem.
Your answer
Follow this Question
Related Questions
Screen Space - Camera makes bullets fly in wrong directions 1 Answer
Missle/Bullet script. C# 2 Answers
Particles disappear when the parent rotates,My particles disappear when the parent rotates 0 Answers
Why isn't this code working? 1 Answer
Can't find a way to add particle effects to a collision 2 Answers