Search Unity

Unable To Move Vertical ingame

Discussion in 'Scripting' started by deadmanmad, May 26, 2020.

  1. deadmanmad

    deadmanmad

    Joined:
    Jan 26, 2018
    Posts:
    1
    This is my Code
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class PlayerController : MonoBehaviour
    {



    public float speed = 18;

    private Rigidbody2D rig;

    Vector2 movement;
    // Use this for initialization
    void Start()
    {
    rig = GetComponent<Rigidbody2D>();

    }

    // Update is called once per frame
    void Update()
    {
    float hAxis = Input.GetAxis("Horizontal");
    float vAxis = Input.GetAxis("Vertical");

    Vector3 movement = new Vector3(hAxis, 0, vAxis) * speed * Time.deltaTime;

    rig.MovePosition(transform.position + movement);

    }
    }
    I checked most things but now I just want to know if it's an error with the code