Search Unity

Help with this FPS control script

Discussion in 'Editor & General Support' started by Lunaris76, Aug 10, 2019.

  1. Lunaris76

    Lunaris76

    Joined:
    Feb 26, 2019
    Posts:
    4
    Hello.

    I'm fairly new with Unity. This seems awesome and I tried a few tutorials with older versions (including Tanks! which are a hit amongst my students).

    I am trying to set up a new FPS controller here.

    But so far I am having something that isnt working.

    I have set up my InputControls named FPS. Everything seems to look like it should work but when I put up my script, only strafingSpeed and walkspeed appears. No inputcontrols selection. So nothing works.

    So I am stuck. Can someone help me?

    Thanks alot

    Lunaris76

    BTW sorry if I didnt put it up in the good thread. If so just point me out where it belongs... this forum is huge!

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.InputSystem;
    5.  
    6. public class FPScontroller : MonoBehaviour
    7. {
    8.     [SerializeField] private InputControl inputcontrol;
    9.  
    10.     private CharacterController myCC;
    11.  
    12.     private Vector2 moveAxis;
    13.  
    14.     [SerializeField] private float walkSpeed;
    15.     [SerializeField] private float strafingSpeed;
    16.  
    17.     private void OnEnable()
    18.     {
    19.         inputcontrol.FPS.Move.performed += MovementInput;
    20.         inputcontrol.FPS.Move.Enable();
    21.  
    22.     }
    23.  
    24.     private void OnDisable()
    25.     {
    26.         inputcontrol.FPS.Move.performed -= MovementInput;
    27.         inputcontrol.FPS.Move.Disable();
    28.     }
    29.  
    30.  
    31.     void Start()
    32.     {
    33.         myCC = GetComponent<CharacterController>();
    34.     }
    35.  
    36.     private void Update()
    37.     {
    38.         if (moveAxis != Vector2.zero || !myCC.isGrounded)
    39.         {
    40.             PlayerMovement();
    41.         }
    42.     }
    43.  
    44.     void PlayerMovement()
    45.     {
    46.         Vector3 movement = Vector3.zero;
    47.         movement += transform.forward * moveAxis.y * walkSpeed * Time.deltaTime;
    48.         movement += transform.right * moveAxis.x * strafingSpeed * Time.deltaTime;
    49.         movement += Physics.gravity;
    50.         myCC.Move(movement);
    51.     }
    52.  
    53.     private void MovementInput(InputAction.CallbackContext context)
    54.     {
    55.         moveAxis = context.ReadValue<Vector2>();
    56.     }
    57. }
    58.  
     
  2. - Do you have any errors in the console? What are those?
    - Did you install the Input System package in the Package Manager in Unity Editor?
     
  3. Lunaris76

    Lunaris76

    Joined:
    Feb 26, 2019
    Posts:
    4
    Yes I have installed the Input System Package

    And no I dont get any errors anymore. I just cant see my Input Control variable in the inspector window so I cant assign it anything. So it just doesnt work.
     
  4. Lunaris76

    Lunaris76

    Joined:
    Feb 26, 2019
    Posts:
    4
    So what do I do?