Particles not working and Input System question

Particle Error
The particles are not bouncing from the walls, no matter what I do. I tried changing it into 0, doesn’t work.
The enemy is also not dying from the lasers. I tried fixing it, but it is not working but just going through the enemy.

I am trying to do this in my code

        if (Input.GetButton("Fire1")) //Trigger left and right lasers
        {
            SetLasersActiveL(true); SetLasersActiveR(true);
        }
        else
        {
            SetLasersActiveL(false); SetLasersActiveR(false);
        } 

or this

        if (Input.GetKeyDown(KeyCode.Space)) //This code should work, right???
        {
            SetLasersActiveL(true); SetLasersActiveR(true);   
        }
        else
        {
            SetLasersActiveL(false); SetLasersActiveR(false);
        }

This should supposedly make it so that if you press space, both thrusters (left and right) should shoot the lasers. If you press right alt, only the left thruster should shoot. Same with right ctrl but with the right thruster shooting. This is not happening and space is not launching both lasers.

Hi @RishMa_STV_GameDev,

Do the walls have got “solid” (= non-trigger) colliders attached? Does the Particle System have got the “Collision” module enabled? Do the enemies have got colliders attached? Without colliders and without the “physics” involved, no collision event will happen.

How did you check that the if/else is not working? Have you already tried to add Debug.Logs to your code to see what is going on during runtime?

Bear in mind that GetKeyDown returns true in one frame only. If you execute your code in Update, the if-block will be executed in one frame, and the else in the next frame.

Furthermore, check in your SetLasersActiveL and SetLasersActiveR methods if the particle system is already playing before you call the Play method on it. Otherwise, it might be that it simply restarts each time Play gets called on it.

I tried all of your solutions, however, it still doesn’t work.

Here is the project link on Google Drive.
https://drive.google.com/drive/folders/1sDrKYCnkioPhb7ceg4FYz4WsCBQTGTW_?usp=sharing

I checked your project.

Your particles’ Collision Type is set to Plane, it should be set to World for it to bounce and hit enemies.

As for your code that fires the 4 lasers at the same time, it doesn’t work because you are deactivating them right after you activate them.

I did this to your code, and it works. Click on this sentence to see the code.
    void ProcessFiring()
    {
        if (Input.GetButton("Fire1")) //Left and Right Lasers
        {
            SetLasersActiveRL(true);
        }
        else
        {
            SetLasersActiveRL(false);
        }

        if (Input.GetButton("Fire2")) //Right Lasers
        {
            SetLasersActiveR(true);
        }
        else
        {
            //SetLasersActiveR(false);
        }

        if (Input.GetButton("Fire3")) //Left Lasers
        {
            SetLasersActiveL(true);
        }
        else
        {
            //SetLasersActiveL(false);
        }
    }

I just commented out those calls that were deactivating the lasers. You can remove those else statements.

Yes, thank you! It’s working now!

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms