- Home /
How can I make 2D movement less jerky on a controller, with velocity and such?
I'm trying to make a top-down dungeon crawler, and I want the player to have some velocity when they move and slow down slightly before changing direction. It works great with the keyboard, but when I use a controller the movement is very snappy and jerky, with no velocity at all. How can I fix this?
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public Vector2 movement;
public Rigidbody2D rigidbodyComponent;
public float inputX, inputY;
public int speed = 700;
void Update()
{
if (name == "Player 1")
{
inputX = Input.GetAxis(PlayerInfo.p1Horizontal);
inputY = Input.GetAxis(PlayerInfo.p1Vertical);
}
if (name == "Player 2")
{
inputX = Input.GetAxis(PlayerInfo.p2Horizontal);
inputY = Input.GetAxis(PlayerInfo.p2Vertical);
}
if (name == "Player 3")
{
inputX = Input.GetAxis(PlayerInfo.p3Horizontal);
inputY = Input.GetAxis(PlayerInfo.p3Vertical);
}
if (name == "Player 4")
{
inputX = Input.GetAxis(PlayerInfo.p4Horizontal);
inputY = Input.GetAxis(PlayerInfo.p4Vertical);
}
movement = new Vector2(inputX, inputY);
}
void FixedUpdate()
{
if (rigidbodyComponent == null) rigidbodyComponent = GetComponent<Rigidbody2D>();
rigidbodyComponent.velocity = movement * speed;
}
}
Comment
Your answer
Follow this Question
Related Questions
Character movement problem, floats away 1 Answer
2D Directional top down movement,Topdown 2d Directional Movement 0 Answers
How do I make my character's movement less floaty? 1 Answer
Having problems with animation and movement of 2D Character 0 Answers
Top down 2d movement without being affected by rotation 2 Answers