Currently, I am attempting to make a 2D 8-bit space RPG thing where the player moves around on procedurally generated planets following some sort of quest. I have the terrain generation all set up, but I am stuck on making my character move. I have not yet implemented jumping (I want to get this out of the way first), but when I try to move right, everything will work as expected, until suddenly, my character completely stops.
Upon writing Input.GetAxisRaw(“Horizontal”) and transform.position.x to the console, I found out that nothing changed to the input (still was at 1 or -1), yet the position didn’t even move the slightest. I do have animations set up, but disabling the Animator component does not help. All the tiles for the planets are made from prefabs, and each has a square collider, which I have checked, and made sure that they are not acting out of the ordinary. When the character halts, he is not colliding with anything. The rigidbody2d has continuous collision detection, a gravity scale of 15, and has constrained rotation along the z axis.
I hope that this problem can be rectified soon, as my small indie team and I are working towards a deadline. Here is the only script controlling or manipulating the character in any way (the character controller):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour {
private Animator playerAnimator;
public float moveSpeed; // set to 5 in editor
// Use this for initialization
void Start () {
playerAnimator = GetComponent<Animator> ();
}
// Update is called once per frame
void Update () {
//Handling animations
if (Input.GetAxisRaw ("Horizontal") == 1.0f) { //Moving right
setWalkingDirection (4);
} else if (Input.GetAxisRaw ("Horizontal") == -1.0f) { // Moving left
setWalkingDirection (3);
} else { // Not moving at all
setWalkingDirection (0);
}
//Player input
Vector2 move = new Vector2(Input.GetAxisRaw("Horizontal"), 0.0f) * moveSpeed;
GetComponent<Rigidbody2D> ().velocity = move;
}
public void setWalkingDirection(int direction) {
playerAnimator.SetInteger ("WalkingDirection", direction);
}
}