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

Need Help trying to move around basic 2D character

Discussion in 'Editor & General Support' started by EUBall, Sep 10, 2020.

  1. EUBall

    EUBall

    Joined:
    Sep 10, 2020
    Posts:
    5
    So Im trying to make a 2D canada move around on a plane (left, right, up, and down.)
    Here is my code:


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

    public class PlayerController : MonoBehaviour{

    public float speed;

    private Rigidbody2D rb;
    private Vector2 moveVelocity;

    void Start(){

    rb = GetComponent<Rigidbody2D>();
    }

    void Update(){

    Vector2 moveInput = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("vertical"));
    moveVelocity = moveInput.normalized * speed;
    }


    void FixedUpdate(){

    rb.MovePosition(rb.position + moveVelocity * Time.fixedDeltaTime);
    }
    }


    For some reason I get this error: (ArgumentExeption: Input Axis vertical is not set up.)

    And my canada boi stays stuck in the middle and doesnt move anywhere:


    Ive also set the speed to 10:


    Send help ;-;
     
  2. Valjuin

    Valjuin

    Joined:
    May 22, 2019
    Posts:
    481
    I suspect your Input Axis is named “Vertical” and not “vertical”.

    (Edit Menu - > Project Settings -> Input -> Axes -> Vertical -> Name)
     
    EUBall and PraetorBlue like this.
  3. EUBall

    EUBall

    Joined:
    Sep 10, 2020
    Posts:
    5
    Your such a genius, you know that right? Its alive!