Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Keys Down & Mouse Usage (Same Time)

Discussion in 'Editor & General Support' started by MisterSkitz, Aug 29, 2018.

  1. MisterSkitz

    MisterSkitz

    Joined:
    Sep 2, 2015
    Posts:
    833
    I don't know if this is the right forum for this or not. (If not, sorry)

    I have a standard typical controller KeyDown script for a 2D side scroller game. I'm using the X-axis as my left.right direction. Anyway, I've noticed that when I'm holding down the "A" or "D" key for movement that I cannot utilize the left click (GetMouseDown(0)) to fire my weapon. Same problem when I jump. The left click seems disabled.

    I want to be able to move and fire my weapon and/or jump and fire at the same time. But I can't.
    Is this something I can fix with code ?

    I'm assuming the problem is one of three possibilities:
    1) My own keyboard settings ( Don't know how to access that to check )
    2) Unity has a constriction (Hopefully a simple checkbox click if so- Don't know where it would be)
    3) Code is needed (Don't know where to even begin to find this information)
     
  2. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Can you post the code that you are currently using that isn't working as expected?
     
    MisterSkitz likes this.
  3. MisterSkitz

    MisterSkitz

    Joined:
    Sep 2, 2015
    Posts:
    833
    Looks like my Synaptics touchpad on my laptop is the issue. I'm currently looking for a way to resolve this.
     
  4. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
  5. MisterSkitz

    MisterSkitz

    Joined:
    Sep 2, 2015
    Posts:
    833
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PMove : MonoBehaviour {
    5.  
    6.     // Use this for initialization
    7.     public float Pspeed = 1.0f;
    8.     public Material rgtFace; // Is actually left facing .. derp
    9.     public Material lftFace;  // Is actually right facing herp ...
    10.     public GameObject player;
    11.  
    12.    public GameObject gun = Pshoot.gun; // Right facing gun
    13.     public GameObject gun1 = Pshoot.gun1; // Left facing gun
    14.     void Start () {
    15.        
    16.     }
    17.    
    18.     // Update is called once per frame
    19.     void Update () {
    20.  
    21.         transform.Translate(Pspeed * Input.GetAxis("Horizontal") * Time.deltaTime,0f,0f);
    22.  
    23.         if (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow)) {
    24.            GetComponent<Renderer>().material = rgtFace;
    25.             gun.SetActive(false);
    26.             gun1.SetActive(true);
    27.          
    28.         }
    29.         if (Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow))
    30.         {
    31.            
    32.             GetComponent<Renderer>().material = lftFace;
    33.             gun.SetActive(true);
    34.             gun1.SetActive(false);
    35.          
    36.         }
    37.  
    38.      
    39.  
    40.     }
    41.  
    42.  
    43.  
    44.  
    45. }
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PJump : MonoBehaviour {
    5.  
    6.     // Use this for initialization
    7.     public float jump1 = 5.0f;
    8.     private bool onGround;
    9.     //private bool dblJump;
    10.  
    11.     public Rigidbody player;
    12.  
    13.     void Start () {
    14.         player = GetComponent<Rigidbody>();
    15.         onGround = true;
    16.        
    17.        
    18.     }
    19.    
    20.     // Update is called once per frame
    21.     void Update () {
    22.  
    23.      
    24.         if (onGround == true) {
    25.  
    26.             if (Input.GetKeyDown(KeyCode.Space))
    27.             {
    28.  
    29.                     player.velocity = new Vector3(0, jump1, 0);
    30.                     onGround = false;
    31.                // Debug.Log("The onGround is False");
    32.                    
    33.                  
    34.                                            
    35.             }          
    36.  
    37.  
    38.         }    
    39.        
    40.     }
    41.  
    42.     void OnCollisionEnter(Collision collision) {
    43.         if (collision.gameObject.tag == "Ground") {
    44.             onGround = true;
    45.            }
    46.      
    47.     }
    48.  
    49.    
    50. }
    51.  
     
  6. MisterSkitz

    MisterSkitz

    Joined:
    Sep 2, 2015
    Posts:
    833
    I honestly don't think it's the code, brutha. But lemme know if ya see something. Thanks! :)
     
  7. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    I don't see GetMouseDown(0) in your code? And can you elaborate regarding Synaptics touchpad? Does it work with an external mouse?
     
  8. MisterSkitz

    MisterSkitz

    Joined:
    Sep 2, 2015
    Posts:
    833
    My bad... Forgot about the shooting script

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Pshoot : MonoBehaviour
    5. {
    6.  
    7.     // Use this for initialization
    8.     float speed = 500;
    9.     public GameObject bullet;
    10.  
    11.  
    12.    public static GameObject gun; // The right facing gun
    13.     public static GameObject gun1; // left facing gun
    14.  
    15.    public  Transform bulletSpawn;
    16.  
    17.     //GameObject enemy = Enemies.CurrentEnemyType;
    18.  
    19.  
    20.     void Start () {
    21.  
    22.        bulletSpawn = GetComponent<Transform>();
    23.         Debug.Log(bulletSpawn);
    24.    
    25.     }
    26.    
    27.     // Update is called once per frame
    28.     void Update () {
    29.  
    30.         if (Input.GetMouseButtonDown(0))
    31.         {
    32.             Fire();
    33.            // Debug.Log("LEFT CLICK ACTIVATED");
    34.  
    35.         }
    36.  
    37.  
    38.  
    39.     }
    40.  
    41.    public void Fire()
    42.     {
    43.  
    44.         GameObject tempBullet = Instantiate(bullet, transform.position, transform.rotation) as GameObject;
    45.         Rigidbody tempRigidbodyBullet = tempBullet.GetComponent<Rigidbody>();
    46.         tempRigidbodyBullet.AddForce(tempRigidbodyBullet.transform.forward * speed);
    47.         Destroy(tempBullet, 1f);
    48.         //StartCoroutine(Wait());
    49.         GetComponent<AudioSource>().Play();
    50.        // Delay.Wait2();
    51.  
    52.         //Vector2 firePos = Vector2(bulletSpawn.position.x, bulletSpawn.position.y);
    53.  
    54.  
    55.     }
    56.  
    57.     IEnumerator Wait()
    58.     {
    59.  
    60.         yield return new WaitForSeconds(2);
    61.  
    62.     }
    63.  
    64.     void OnTriggerEnter(Collider other)
    65.     {
    66.         if (other.tag == "Enemy1" || other.tag == "Boss")
    67.         {
    68.             Destroy(bullet);
    69.            
    70.  
    71.  
    72.         }
    73.  
    74.         }
    75. }
     
  9. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    So it works with an external mouse, but not your trackpad?
     
  10. MisterSkitz

    MisterSkitz

    Joined:
    Sep 2, 2015
    Posts:
    833
    I haven't actually tried plugging my mouse in. To be honest, I just found out about the synaptics about 30 minutes after posting this thread. I suppose that was my poor researching skills. I even named it #1 issue upon posting. derp :p

    I think I'm going to try and download the Windows 10 driver and see if that helps. However, I'll run a mouse test and see what happens first.
     
  11. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Yes, please test with a mouse. So the trackpad DOES work to fire, as long as you don't hold a keyboard key down at the same time?
     
    MisterSkitz likes this.
  12. MisterSkitz

    MisterSkitz

    Joined:
    Sep 2, 2015
    Posts:
    833
    I can jump/move and shoot if I use my mouse. So the trackpad is 100% the issue.
     
  13. MisterSkitz

    MisterSkitz

    Joined:
    Sep 2, 2015
    Posts:
    833
    Yes, whenever I moving or jumping, the left click doesn't work. I've debug.logged it to death and left click never activated whilst moving or jumping. Works fine with a mouse though.
     
  14. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Thanks for checking! Yes, sounds like a possible issue with the trackpad support. I wonder if a Mac trackpad behaves the same way (that would not be good). But seems like we would have heard about it already, if so.
     
    MisterSkitz likes this.
  15. MisterSkitz

    MisterSkitz

    Joined:
    Sep 2, 2015
    Posts:
    833
    From my understanding, it's just the Lenovo Synaptics touchpad driver. There was another driver mentioned, something like an Eller?
     
  16. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Glad you were able to determine the issue. I'm not familiar with an Eller driver, but you could certainly test.
     
    MisterSkitz likes this.