Search Unity

Death Particles won't show where player dies.

Discussion in '2D' started by edy_sefu41, Mar 14, 2018.

  1. edy_sefu41

    edy_sefu41

    Joined:
    Mar 14, 2018
    Posts:
    14
    ,So I'm working on a 2D platformer, and I got stuck somewhere. I have set up a particle system, one that will show when the player dies and one that will show when the player respawn, the script is EXACTLY as the one in the tutorial that I'm following:


    But my particles won't show on the player when he dies. They will be shown on the default spot that they were created. Like this: http://recordit.co/4C13Wk37uM . I already deleted them from there, and I think that the death particle should be attached to the player or something so it can follow the player and play when he dies. And the respawn particle should be attached to the checkpoints. In the video the guy does nothing about that but they work. Any help? Please, I've been struggling on this for a couple of hours and it's already frustrating

    The script:

    using System.Collections; using UnityEngine;

    public class LevelManager : MonoBehaviour {

    1. public GameObject currentCheckpoint;
    2. private PlayerController player;
    3. public GameObject deathParticle;
    4. public GameObject respawnParticle;
    5. // Use this for initialization
    6. void Start () {
    7. player = FindObjectOfType<PlayerController>();
    8. }
    9. // Update is called once per frame
    10. void Update () {
    11. }
    12. public void RespawnPlayer()
    13. {
    14. Instantiate (deathParticle, player.transform.position, player.transform.rotation);
    15. Debug.Log ("Player Respawn");
    16. player.transform.position = currentCheckpoint.transform.position;
    17. Instantiate(respawnParticle, currentCheckpoint.transform.position, currentCheckpoint.transform.rotation);
    18. }
    }

    Please help me
     
  2. IronManBK

    IronManBK

    Joined:
    Jul 12, 2017
    Posts:
    7
    I havent seen video yet, if you want dead particle play at position of player, it should be child of player, have you check it carefully
     
  3. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    Attaching the particle system to the player would work, but looking at the recording you linked, your player respawns instantly & while the particle system is still playing. You may have to set the particles to emit in world space rather than local space, otherwise you would see them following the player as the system is still playing.
     
  4. edy_sefu41

    edy_sefu41

    Joined:
    Mar 14, 2018
    Posts:
    14
    it don't need to do that, this is my problem: recordit.co/4C13Wk37uM
     
  5. edy_sefu41

    edy_sefu41

    Joined:
    Mar 14, 2018
    Posts:
    14
    and how do i make them emit in world space?
     
  6. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    In the "Particle System" tab (the very first tab, above the "Emission" tab) near the bottom, there is a setting labeled "Simulation Space" that is set to "Local" by default. Try setting it to "World".
     
  7. edy_sefu41

    edy_sefu41

    Joined:
    Mar 14, 2018
    Posts:
    14
    still nothing changed, the particles still play at the beginning
    i don't kow how am i supposed to make them follow the player and play when he dies, and as long as i have them set here i dont think i need to make them the child: https://imgur.com/a/LbWRK
     
  8. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    Then at this point I would start debugging.
    In the Update method, try Debug.Log(player.transform.position) to see if the the values of the player's position are actually changing when the player is moving.
     
  9. edy_sefu41

    edy_sefu41

    Joined:
    Mar 14, 2018
    Posts:
    14
    They do, but they pop up even if i'm not moving. It got to 900 in 10 seconds. https://imgur.com/a/pqXm2
     
  10. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    Maybe you should try with players position as gameobject. Set the tag from the player to "Player", then
    1. private GameObject player;
    7. player = GameObject.FindWithTag ("Player");
     
  11. edy_sefu41

    edy_sefu41

    Joined:
    Mar 14, 2018
    Posts:
    14
    https://imgur.com/a/pqXm2
     
  12. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    just comment the two lines and check if the particles are spawned at the needed position.

    //player.transform.position = currentCheckpoint.transform.position;
    //Instantiate(respawnParticle, currentCheckpoint.transform.position, currentCheckpoint.transform.rotation);

    this error (the name doesn't exist) is because of missing currentCheckpoints deklarations at the scripts beginn.
    public GameObject currentCheckpoint;

    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using UnityEngine;
    4.  
    5. public class LevelManager : MonoBehaviour {
    6.  
    7. public GameObject currentCheckpoint;
    8. private GameObject player;
    9. public GameObject deathParticle;
    10. public GameObject respawnParticle;
    11. // Use this for initialization
    12. void Start () {
    13. player = GameObject.FindWithTag ("Player");
    14. }
    15. // Update is called once per frame
    16. void Update () {
    17. }
    18. public void RespawnPlayer()
    19. {
    20. Instantiate (deathParticle, player.transform.position, player.transform.rotation);
    21. Debug.Log ("Player Respawn");
    22. //player.transform.position = currentCheckpoint.transform.position;
    23. //Instantiate(respawnParticle, currentCheckpoint.transform.position, currentCheckpoint.transform.rotation);
    24. }
    25. }
    26.  
    If this will not work, then check the prefab from the spawned particles (as example, play on awake isn't checked, or order in layer is too low and you cannot see the particles). Try to spawn an other prefab for test (put a sprite in the scene, make a prefab from it and use this prefab instead of particles).
     
    Last edited: Mar 14, 2018
  13. edy_sefu41

    edy_sefu41

    Joined:
    Mar 14, 2018
    Posts:
    14
    I feel like this might work, tho i get this... sorry for being such a newbie, I'm just not familiar with this...
    Can you help me? https://imgur.com/a/DBYEP
     
  14. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    how are you calling the RespawnPlayer() funktion ? Wait, do you have added the tag Player to the player ( ) ? Add this line: if (player != null)

    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using UnityEngine;
    4.  
    5. public class LevelManager : MonoBehaviour {
    6.  
    7. public GameObject currentCheckpoint;
    8. private GameObject player;
    9. public GameObject deathParticle;
    10. public GameObject respawnParticle;
    11. // Use this for initialization
    12. void Start () {
    13. player = GameObject.FindWithTag ("Player");
    14. }
    15. // Update is called once per frame
    16. void Update () {
    17. }
    18. public void RespawnPlayer()
    19. {
    20. if (player != null)
    21. Instantiate (deathParticle, player.transform.position, player.transform.rotation);
    22. Debug.Log ("Player Respawn");
    23. //player.transform.position = currentCheckpoint.transform.position;
    24. //Instantiate(respawnParticle, currentCheckpoint.transform.position, currentCheckpoint.transform.rotation);
    25. }
    26. }
    27.  
    or if you are allready using an other tag for the player, then change the line with used tag
    player = GameObject.FindWithTag ("place here used tag from the tutorial");
     
    Last edited: Mar 14, 2018
  15. edy_sefu41

    edy_sefu41

    Joined:
    Mar 14, 2018
    Posts:
    14
    I tagged the player and it works, i have him tagged as Player so I don't need to change anything, but now when I play the game with your script and the tagged player only the death animation plays now, at the beginning... still not where the player dies, and he doesn't respawn anymore

    http://recordit.co/vTeF0lGIS6
     
  16. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    ok, the line "player = FindObjectOfType<PlayerController>();" was working then :D

    something is wrong with the spawned prefab. Try next. create new particle system, make its prefab (drag&drop created particle system into assets folder. And then place this prefab into the players script instead of old "deathParticle")

    can you make screenshot from the "deathParticle" prefab ? I will check prefab and its inspector. I think, that the particle system can be child of an other object.
     
    Last edited: Mar 14, 2018
  17. edy_sefu41

    edy_sefu41

    Joined:
    Mar 14, 2018
    Posts:
    14
    Dude you're a god! It almost works! Now the animation is supposed to play where the played dies, and it shows me that the particle is there, but the player won't respawn. Please help me out with this and I'm done! <3

    https://imgur.com/a/NGpIY
     
  18. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    Just use your old script from the first post and this new prefab.

    I am not sure, I think you have created an empty gameobject, and then the particle system was added to this empty gameobject. Now, if you are spawning the particle system, the main object will be spawned at needed position but the local position from the particle system is an other. You can try to unchild the particle system (if it is a child) or change its local (child) position to (0, 0, 0).
     
    Last edited: Mar 14, 2018
  19. edy_sefu41

    edy_sefu41

    Joined:
    Mar 14, 2018
    Posts:
    14
    I changed the script, and I'm back to the first problem, but only with the green respawning particle. The death particles are still showing there at the spikes like they should be playing, but they don't. I think I need to remake the green particles like I remade the death ones. But i don't know why they don't show... Is there something wrong in the inspector?

    http://recordit.co/H5DKM4mH6E
     
  20. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    The script is ok, something is wrong with the spawned prefabs. Try to rework them.
     
    razvaniorga and edy_sefu41 like this.
  21. edy_sefu41

    edy_sefu41

    Joined:
    Mar 14, 2018
    Posts:
    14
    MAN I MADE IT! first i recreated the respawn particle and it worked fine, so i compared them both and i saw that the death particles didnt have the play on awake checked, so i checked it and it finally works! thanks a lot for your wasted time, you're the best <3