vandim
1
So I am trying to make my character not suddenly stop when I release the arrow keys.
Just like in a mario game where when you stop running, mario slides a little bit.
Vector3 movement;
void FixedUpdate()
{
float h = Input.GetAxisRaw ("Horizontal");
float v = Input.GetAxisRaw("Vertical");
Move (h, v);
}
void Move (float h, float v)
{
movement.Set(h, 0f, v);
movement = movement.normalized * speed * Time.deltaTime;
rb.MovePosition(transform.position + movement);
}
float horizontal ;
float vertical ;
void FixedUpdate()
{
float h = Input.GetAxisRaw (“Horizontal”);
float v = Input.GetAxisRaw(“Vertical”);
if( Mathf.Abs( h ) > 0.001f )
horizontal = h ;
if( Mathf.Abs( v ) > 0.001f )
vertical = v ;
horizontal = Mathf.Lerp( horizontal, 0, Time.fixedDeltaTime ) ;
vertical = Mathf.Lerp( vertical, 0, Time.fixedDeltaTime ) ;
Move (horizontal, vertical);
}