- Home /
problem resolved on it's own
moving player top down,movement in unity 2d
Hi, i'm very new to unity and coding. I'm following Brackey's tutorial on top down movement for my game in 2d, here's the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement
{
public float moveSpeed = 5f;
public Rigidbody2D rb;
Vector2 movement;
// Update is called once per frame
void Update()
{
movement.x = Input.GetAxisRaw("Horizontal");
movement.y = Input.GetAxisRaw("Vertical");
}
void FixedUpdate()
{
rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime );
}
}
But i have two problems: 1. My character won't move at all (tbh i don't even know if i did the right thing: i imported a tilesheet with all the movement, sliced and made a tilemap to place one of the image in the scene) 2. Unity won't stop telling me that "Input Axis vertical is not set up".
If someone can help please do, i've been looking for a solution for hours
Thanks :)
(I am waiting to be able to answer my post because administrator doesn't want me to but: yes rb does appear in the inspector and the speed is at 5, and the "Vertical" isn't mispelled so i don'tknow where the problem come from)
EDIT: i restarted unity and i don't know how, but now my character can move left and right, still not up and down
EDIT 2: I verified and there are no typos that i can see
EDIT 3: Tried to put a "v" instead in the manager of a "V", does not work :(
FINAL EDIT: now it's working after closing and re opening unity and visual studio, still have no idea what the problem was but thanks!
https://answers.unity.com/questions/1301591/error-input-axis-vertical-is-not-set-up.html
https://answers.unity.com/questions/325483/error-input-axis-not-set-up.html
Also, ensure the rb
variable is correctly provided in the inspector, and that moveSpeed
is greater than 0 in the inspector.
And having a screenshot of your player object would help diagnose the other problems you may have.
Vertical
!= vertical
Can you show your Input Manager please? And confirm your code is Input.GetAxisRaw("Vertical")
not Input.GetAxisRaw("vertical")
Can you try chaning the name Vertical
to vertical
in the Input Manager?
If it actually solves your issue, you most likely put vertical
instead of Vertical
in your code.
Follow this Question
Related Questions
Destroy a gameObject in the scene if instantiate the same gameObject 0 Answers
How to make a sprite respond to a specific color? 0 Answers
Why Is there A slight jitteryness on player movement and camera? 0 Answers
how to make a 2d character three-dimensional? 1 Answer
[Solved] Does Unity's 2D Tilemap Editor 1.0.0 Include Rule Tiles? 1 Answer