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. Dismiss Notice

Input (PC/ANDROID)

Discussion in 'Input System' started by GeorgeSaint, Mar 13, 2021.

  1. GeorgeSaint

    GeorgeSaint

    Joined:
    Aug 16, 2018
    Posts:
    8
    Hello!
    please forgive me for a dumb question!! but...
    Just started to learn this awesome Engine, starting from online course.
    So i try to implement this Asset:
    Joystick Pack | Input Management | Unity Asset Store
    but it does not work!, i was doing just like described on PDF.
    And build new Project with this:
    2D Roguelike | Tutorial Projects | Unity Asset Store
    That Joystick Pack did't work.
    Same result on different projects, Joystick moving like on any mobile devices but player stand still.
    i've start to think maybe i need to implement to my player movement code, but i just started to learn and don't know where or what to do.
    here is walking script that i've trying to work with.
    Maybe Somebody knew, or know some issues with this...
    My Unity version: 2019.4.22.f1 Personal
    Thank You!!!

    Code (CSharp):
    1. public class Player : MonoBehaviour
    2. {
    3.     private BoxCollider2D boxCollider;
    4.     private Vector3 moveDelta;
    5.     private RaycastHit2D hit;
    6.  
    7.     private void Start()
    8.     {
    9.         boxCollider = GetComponent<BoxCollider2D>();
    10.     }
    11.  
    12.     private void FixedUpdate()
    13.     {
    14.         float x = Input.GetAxisRaw("Horizontal");
    15.         float y = Input.GetAxisRaw("Vertical");
    16.        
    17.         // Reset MoveDelta
    18.         moveDelta = new Vector3(x, y, 0);
    19.      
    20.         ///Swap Sprite Direction
    21.         if (moveDelta.x > 0)
    22.             transform.localScale = Vector3.one;
    23.         else if (moveDelta.x < 0)
    24.             transform.localScale = new Vector3(-1, 1, 1);
    25.      
    26.         ///Collision with blocks and nps, if not null we can't move
    27.         hit = Physics2D.BoxCast(transform.position, boxCollider.size, 0, new Vector2(0, moveDelta.y), Mathf.Abs(moveDelta.y * Time.deltaTime), LayerMask.GetMask("Actor", "Blocking"));
    28.         if (hit.collider == null)
    29.         {
    30.             ///make player to move
    31.             transform.Translate(0, moveDelta.y * Time.deltaTime, 0);
    32.         }
    33.         hit = Physics2D.BoxCast(transform.position, boxCollider.size, 0, new Vector2(moveDelta.x, 0), Mathf.Abs(moveDelta.x * Time.deltaTime), LayerMask.GetMask("Actor", "Blocking"));
    34.         if (hit.collider == null)
    35.         {
    36.             ///make player to move
    37.             transform.Translate(moveDelta.x * Time.deltaTime,0, 0);
    38.         }
    39.     }
    40. }
     
  2. GeorgeSaint

    GeorgeSaint

    Joined:
    Aug 16, 2018
    Posts:
    8