- Home /
How to make my 2D movement smooth
Well yes, I saw many of this questions but no one explained it to me. I want to my character "slide" a little bit after i stop pressing the button.
That depends on how you are implementing the movement. Can you paste here your movement code?
Well now I have no code, because Get Axis was not working properly. I need to write a whole new code, but with that effect.
Answer by Skeasy · Sep 17, 2019 at 03:26 PM
Hi, you could add a physics 2d material with 0.1 friction to your collider. Alternativly ( if you are using "transform.position" or "rigidbody.velocity") you could instead use rigidbody.AddForce(). MfG Skeasy
Thanks! Could you please give me simple code for walking?
@creepero$$anonymous$$
there are many ways
public class movement : $$anonymous$$onoBehaviour { public float speed = 5; private float hori_movement; private float verti_movement;
void Update()
{
hori_movement = Input.GetAxisRaw("Horizontal");
verti_movement = Input.GetAxisRaw("Vertical");
}
private void FixedUpdate()
{
gameObject.GetComponent<Rigidbody2D>().AddForce(new Vector2(hori_movement * speed, verti_movement * speed));
}
}
Well It's not working, but You haven't write in your script what button needs to be pressed.
Your answer
Follow this Question
Related Questions
smooth follow 2d camera runner ios 0 Answers
Player Tips - Have triggers act independently 1 Answer
Rolling Barrels through Platforms 0 Answers
2D Mouse Aiming on Unity 4.3 1 Answer
2d enemy ai 0 Answers