Search Unity

Player Controls are not working

Discussion in 'Getting Started' started by Jainshashank, Dec 28, 2021.

  1. Jainshashank

    Jainshashank

    Joined:
    Dec 28, 2021
    Posts:
    1
    Hello everyone I have just started with unity and I am building a rollaball game by watching unity tutorials I am doing all things right but my player is not moving on pressing keyboards controls.
    Anyone Please Help!!!
    I am also new in using C# so all this code is from tutorials.

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.InputSystem;

    public class PlayerController : MonoBehaviour
    {
    public float speed = 0;

    private Rigidbody rb;

    private float movementX;
    private float movementY;

    // Start is called before the first frame update
    void Start()
    {
    rb = GetComponent<Rigidbody>();
    }

    private void OnMove(InputValue movementValue)
    {
    Vector2 movementVector = movementValue.Get<Vector2>();

    movementX = movementVector.x;
    movementY = movementVector.y;
    }

    private void FixedUpdate()
    {
    Vector3 movement = new Vector3(movementX, 0.0f, movementY);

    rb.AddForce(movement * speed);
    }

    }[/code]
     
  2. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    Welcome to the forums! Thanks for trying to use the code tags. Looks like you missed or accidentally removed the opening one, though. Just something to watch for next time.

    Looking at your code, it doesn't look like you're actually processing player input anywhere. You have an OnMove method defined, but it isn't being used anywhere. Go through your tutorial again and be sure you didn't miss anything.
     
  3. sidrkyani

    sidrkyani

    Joined:
    Dec 28, 2021
    Posts:
    2
    Theisame question I was posted on this forum but not known why the admin delete the post I also wanna know the answer....