- Home /
How do I make my character's movement less floaty?
I'm making a top down 2D dungeon crawler and I'm having a problem with movement. It's too "floaty", kind of like your character is running on ice. I still want to have some realistic physics in the movement, but I don't know how to find that middle ground between jerky and floaty. I also have keyboard and controller support in the game.
 using UnityEngine;
 
 public class PlayerMovement : MonoBehaviour
 {
     public Vector2 movement;
     public Rigidbody2D rigidbodyComponent;
     public float inputX, inputY;
     public Vector2 speed = new Vector2(50, 50);
 
     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(speed.x * inputX, speed.y * inputY);
 
     }
 
     void FixedUpdate()
     {
         if (rigidbodyComponent == null) rigidbodyComponent = GetComponent<Rigidbody2D>();
         rigidbodyComponent.AddForce(movement);
     }
 }
Answer by Harinezumi · Jul 31, 2018 at 07:10 AM
The character works correctly according to the law of conservation of momentum. You can slow down either by increasing the friction using a physics material with high(er) friction and assigning it to the collider, or you can simply increase the drag variable of the rigidbody which is a velocity dependent slowing factor (between 2 and 10 is usually a good value).
 You can create a physics material by right clicking in the project view and selecting "Physics material" from the menu.
 
 You can do either, probably even both, but I would recommend just going with the drag, as it is simpler. 
 
Your answer
 
 
             Follow this Question
Related Questions
Weird Rigidbody2D.velocity.x problem, float out of control 0 Answers
2D Directional top down movement,Topdown 2d Directional Movement 0 Answers
How do I make my character move on the Z axis on 2d rigidbody? 0 Answers
How can I make 2D movement less jerky on a controller, with velocity and such? 0 Answers
Rigidbody2D x velocity not moving unless placed in FixedUpdate 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                