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

Android FPS Controller

Discussion in 'Scripting' started by iRuDz, Jul 25, 2016.

  1. iRuDz

    iRuDz

    Joined:
    Feb 1, 2016
    Posts:
    39
    I'm seriously in desperate need of help, searching the entire internet for tutorials about this, but surprisingly, there is none. Give me an idea on how to make an Android FPS Controller that has a joystick for moving around, and you drag the screen to look around. Please make it simple and clear as i am not that good of a coder.
     
    yousafyousaf and JorgeAmVF like this.
  2. Polymorphik

    Polymorphik

    Joined:
    Jul 25, 2014
    Posts:
    599
    What version of Unity are using?
     
  3. iRuDz

    iRuDz

    Joined:
    Feb 1, 2016
    Posts:
    39
    5.3.4
     
  4. Polymorphik

    Polymorphik

    Joined:
    Jul 25, 2014
    Posts:
    599
    Ah ok, so there are couple of ways of doing this none of which are tied to Android specific devices. You want to try and avoid doing platform specific things when multiple platforms share some underlying features for instance a touch screen.

    That being said this is how I would go about doing the FPS controller.

    1.) Use Unity's UI system for movement.
    i.) Create a button
    ii.) Implement UnityEngine.Events interfaces (IPointerDownHandler, IPointerUpHandler, IPointerExitHandler, IPointerDragHandler).
    iii.) Using the interfaces you can then move the Button around like a joystick. You can then use the deltas and reroute that information to a Script to move the player around.
    2.) Use Touch for rotation
    i.) Loop through all touches in a for-loop
    ii.) Check which touch is on the right side of the screen (Camera.ScreenToViewportPoint) *Replace Input.mousePosition with Touch[index].position ** Viewport is great because it gives you values between 0 -> 1 (X: 0 = Left Side, 1 = Right Side Y: 0 = Bottom, 1 = Top)
    iii.) Cache the last known position, use the deltas between Touch.position to give you rotation.
     
    phungtu081 and JorgeAmVF like this.
  5. Polymorphik

    Polymorphik

    Joined:
    Jul 25, 2014
    Posts:
    599
    The Unity Example Assets has a cross-platform Touch controller but it uses 2 buttons to get movement and rotation. You can look into that and see how it was implemented.
     
    JorgeAmVF likes this.
  6. iRuDz

    iRuDz

    Joined:
    Feb 1, 2016
    Posts:
    39
    Thank you so much, i really appreciate it.
     
  7. yousafyousaf

    yousafyousaf

    Joined:
    Apr 15, 2018
    Posts:
    5
    Have you find the resource how to make ????????????