Search Unity

my gameobject stopped moving when i switced to joystick

Discussion in 'Scripting' started by brunoenvia, Oct 20, 2019.

  1. brunoenvia

    brunoenvia

    Joined:
    Aug 5, 2019
    Posts:
    94
    idk why this happened, my gameobject was moving with keyboard using crossplatforminput
    but then i switched to joystick and tried to change back to keyboard and now it doesn't move.
    any idea why this happened?
    it doesn't jump either

    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityStandardAssets.CrossPlatformInput;
    6.  
    7. public class PlayerMovement : MonoBehaviour
    8. {
    9.     [SerializeField] GameObject Player;
    10.     Rigidbody playerRigidBody;
    11.     Vector3 movement;
    12.     Renderer playerColor;
    13.     [SerializeField] int speed = 10;
    14.     [SerializeField] float jumpForce = 5f;
    15.     [SerializeField] bool hasJumpedOnce = false;
    16.    // [SerializeField] bl_Joystick joystick;
    17.  
    18.     // Start is called before the first frame update
    19.     void Start()
    20.     {
    21.         playerRigidBody = Player.GetComponent<Rigidbody>();
    22.         playerColor = GetComponent<Renderer>();
    23.         hasJumpedOnce = false;
    24.  
    25.     }
    26.  
    27.     // Update is called once per frame
    28.     void Update()
    29.     {
    30.         HorizontalVerticalMovement();
    31.         Jump();
    32.      
    33.     }
    34.  
    35.  
    36.  
    37.     private void Jump()
    38.     {
    39.         if (CrossPlatformInputManager.GetButtonDown("Jump") && hasJumpedOnce == false)
    40.         {
    41.             Vector3 jump = new Vector3(0, jumpForce, 0);
    42.             playerRigidBody.AddForce(jump, ForceMode.Impulse);          
    43.             hasJumpedOnce = true;
    44.  
    45.          
    46.         }
    47.  
    48.         else
    49.         {
    50.             return;
    51.         }
    52.      
    53.     }
    54.  
    55.     private void OnCollisionEnter(Collision collision)
    56.     {
    57.         if (collision.gameObject.tag == "Ground")
    58.         {
    59.             hasJumpedOnce = false;
    60.         }
    61.     }
    62.  
    63.  
    64.  
    65.     private void HorizontalVerticalMovement()
    66.     {      
    67.  
    68.         float verticalMovement = CrossPlatformInputManager.GetAxis("Vertical");
    69.         movement = new Vector3(0, 0, verticalMovement * speed * Time.deltaTime);
    70.         playerRigidBody.AddForce(movement);
    71.  
    72.         float horizontalMovement = CrossPlatformInputManager.GetAxis("Horizontal");
    73.         movement = new Vector3(horizontalMovement * speed * Time.deltaTime, 0, 0);
    74.         playerRigidBody.AddForce(movement);
    75.  
    76.         Debug.Log(horizontalMovement);
    77.         Debug.Log(verticalMovement);
    78.     }
    79. }
    80.  
     
  2. csofranz

    csofranz

    Joined:
    Apr 29, 2017
    Posts:
    1,556
    Have you checked how Unity's Input Manager is set up? Perhaps you (or someone else) have switched the assignments for Horizontal and Vertical? What does your log say are the values for horizontal and vertical?
     
  3. brunoenvia

    brunoenvia

    Joined:
    Aug 5, 2019
    Posts:
    94
    That's what I find strange I didn't Change anything