Controls are no more working after header and tooltip

I can shoot lasers with left Ctrl button but unable to move my ship with WASD or Arrow keys After Adding tooltip and headers and
changing code in Active fire Method/Function ,it was all fine before this lecture.

I am also Adding screenshot of my player ship Inspector

You Can See My Code Below:

 using System;

 using System.Collections;

 using System.Collections.Generic;

 using UnityEngine;

 public class PlayerControls : MonoBehaviour

{

[Header("General Setup Settings")]

[Tooltip("How fast ship moves up and down based upon player input")]

[SerializeField] float controlSpeed = 10f;

[Tooltip("How fast player moves horizontally")] [SerializeField] float xRange = 10f;

[Tooltip("How fast player moves vertically")] [SerializeField] float yRange = 7f;



[Header("Laser gun array")]

[Tooltip("Add all player lasers here")]

[SerializeField] GameObject[] lasers;

[Header("Screen position based tuning")]

[SerializeField] float positionPitchFactor = -2f;

[SerializeField] float positionYawFactor = 2f;

[Header("Player input based tuning")]

[SerializeField] float controlPitchFactor = -10f;

[SerializeField] float controlRollFactor = -20f;

float xThrow, yThrow;

void Update()

{

    ProcessTranslation();

    ProcessRotation();

    ProcessFiring();

}

void ProcessRotation()

{

    float pitchDueToPosition = transform.localPosition.y * positionPitchFactor;

    float pitchDueToControlThrow = yThrow * controlPitchFactor;

   

    float pitch = pitchDueToPosition + pitchDueToControlThrow;

    float yaw = transform.localPosition.x * positionYawFactor;

    float roll = xThrow * controlRollFactor;

   

    transform.localRotation = Quaternion.Euler(pitch, yaw, roll);

}

void ProcessTranslation()

{

    xThrow = Input.GetAxis("Horizontal");

    yThrow = Input.GetAxis("Vertical");

    float xOffset = xThrow * Time.deltaTime * controlSpeed;

    float rawXPos = transform.localPosition.x + xOffset;

    float clampedXPos = Mathf.Clamp(rawXPos, -xRange, xRange);

    float yOffset = yThrow * Time.deltaTime * controlSpeed;

    float rawYPos = transform.localPosition.y + yOffset;

    float clampedYPos = Mathf.Clamp(rawYPos, -yRange, yRange);

    transform.localPosition = new Vector3(clampedXPos, clampedYPos, transform.localPosition.z);

}

void ProcessFiring()

{

    if (Input.GetButton("Fire1"))

    {

        SetLasersActive(true);

    }

    else

    {

        SetLasersActive(false);

    }

}

void SetLasersActive(bool isActive)

{

    foreach (GameObject laser in lasers)

    {

        var emissionModule = laser.GetComponent<ParticleSystem>().emission;

        emissionModule.enabled = isActive;

    }

  }
}

Hi TR_GameDeveloper,

Welcome to our community! :slight_smile:

This problem is really odd. Have you already tried to restart Unity and Visual Studio Code?

If the issue persists, try to remove the tooltips and headers. Save your script, and test your game again. If the issue still persists, it was probably just a coincidence that the problem appeared after you added the tooltips and headers. In that case, undo the changes to retrieve your tooltips and headers, and save your script again.

Then add Debug.Logs to your code to see if you get the expected values at runtime. Maybe the problem is caused by the user input system. That’s impossible to tell just by reading the code because those values get generated at runtime only, not while typing or reading the code.

Please let me know if this helped you solve the problem or if you still need help with this. :slight_smile:


See also:

it is still not working as i restarted unity and VScode and also removed the headers and tooltips . please help me and you can also ask about any information you want about it to recognize the problem and its solution.

EDIT:
one thing i noticed now that there was/is no problem with my code but its just something in Timeline because when the timeline ends i become able to control the ship properly that means the timeline is not allowing me to move my ship up/down/left/right . this is because when i tuned and tweaked my timeline a little bit after that it (this problem) starts . there is no problem with Headers or Tooltips .please help

Thank you. That’s crucial information. A common mistake in this game project is to animate the PlayerShip. Only the PlayerRig (= the parent of PlayerShip) may be animated.

If the PlayerShip gets animated, the animation overrides the changes applied by your code. In that case, your code works perfectly fine but the game looks as if the code were not working. That’s why using Debug.Log is important because it is easy to misinterpret what’s going on in the game. In this case, you could waste hours or days looking for problems in your code while there is no problem there.

For testing purposes, you could disable the Timeline game object, and “play” your game. If the spaceship suddenly moves as expected, you know that the problem is in the Timeline. In that case, delete the “wrong” animation. If that breaks your animation, delete all animations affecting the PlayerRig and its children. It’s usually faster to redo the animation than to try to fix dozens of issues in a rather simple animation.

Did this fix it?

you mean that i have to delete the complete animation track and remake it?

If the PlayerShip is not animated, you don’t have to redo the animation. If the PlayerShip is animated, you have to remove the animation that animates the PlayerShip.

1 Like

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

Privacy & Terms