Trying to add particle effects to rotation, Help appreciated!

Hello all I am attempting to add some particle effects to my right and left boosters. I have walked through the same steps as the thruster. My code is below. Does anyone know why my booster animations are not showing up in game? I have also selected the correct prefab for each in my inspector. All my other particle effects work fine.
Thoughts appreciated.

    private void RespondToRotateInput()
    {
        rigidBody.freezeRotation = true; //take manual control of ship

        float rotationSpeed = rcsThrust * Time.deltaTime; 

        if (Input.GetKey(KeyCode.A))  
        {
            rotateRight(rotationSpeed);
        }
        else { rightThrust.Stop();  }

        if (Input.GetKey(KeyCode.D))
        {
            rotateLeft(rotationSpeed);
        }
        else
        {
            leftThrust.Stop();
        }
         rigidBody.freezeRotation = false; //resume physics control
    }

    private void rotateLeft(float rotationSpeed)
    {
        transform.Rotate(-Vector3.forward * rotationSpeed);   
        if (!rightThrust.isPlaying)
        {
            rightThrust.Play();
        }
    }

    private void rotateRight(float rotationSpeed)
    {
        
        transform.Rotate(Vector3.forward * rotationSpeed);   
        if (!leftThrust.isPlaying)
        {
            leftThrust.Play();
        }
    }

Hi Weiprecht,

Have you already tried to add Debug.Logs to your code to see what is going on during runtime? I skimmed your code, and it makes sense so far but maybe the particle system gets stopped when it is not supposed to get stopped.

Also check if you assigned the particle systems from your Hierarchy to the fields in the Rocket component.

Thank you Nina for your assistance. I don’t think the Debug.Logs has been explained in the class yet. Is there documentation that explains how it works and how to review the bugs? This would be very useful.

Also, I figured something out. The particles are firing, but only when you push two keys at the same time. Any idea, why they would not fire individually. Do I need to break them out into individual methods so the inputs are taken individually?

Thank you again for your assistance,
Adam

Absolutely. See here: https://docs.unity3d.com/ScriptReference/Debug.Log.html :slight_smile:

Log the following into your console:

Debug.Log(Time.frameCount + " --- A meaningful message.");

Of course, you should replace “A meaningful message” with something meaningful, so you will be able to distinguish between the messages.

At the moment, I have no idea why you have to press two buttons to make the particle system work. It does not make any sense to me but maybe I’m missing something. For testing purposes, you could comment out the Stop code in the else-blocks to see if the respective particle system start playing once you press the corresponding single key.

Thank you Nina. That did not register any bugs. I think the code was written correctly. However, the problem was with the rcsThrust variable, which executed both functions. After I broke them out individually, things started working correctly.

Thank you,
Adam

  //[SerializeField] float rcsThrust = 40f; 
    [SerializeField] float rcsThrustLeft = 40f;
    [SerializeField] float rcsThrustRight = 40f;

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

Good job! :slight_smile:

Privacy & Terms