Ok so I’m not sure if this is a platformer or if it’s top-down or whatever but I’d recommend that you use another method of movement since AddForce always will glide and I never use it to move characters.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour {
public int moveSpeed = 5;
private Rigidbody2D rb2d;
void Start () {
rb2d = GetComponent<Rigidbody2D>();
}
void Update () {
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
rb2d.velocity = new Vector2(h*moveSpeed, v*moveSpeed);
}
You’re using physics to control your character, so unless you specifically dampen movement with something like rb2d.velocity = 0.95f * rb2d.velocity; each frame, the character will continue to have whatever velocity it had last time you applied force.
Yep. Or you turn up the drag value of your rigidbody. Or give your stage a physic material with high friction ( given you use normal Gravitation).
But you definitely need something to tear down the force over time. Otherwise your sprite will endlessly fly with the given force as if it where in space.
Also please make sure, when you use physic commands to use FixedUpdate, because right after fixedUpdate the internal physics process is run. using physics commands in Update will result in odd Behaviours, because Update can be called many or no times before the internal physics calculation (depending on your framerate).