Question by
lalabuy · Oct 27, 2018 at 03:32 PM ·
movementtransform.position
How to make movement smooth?
Here is my example of character movement. I would like to make the movements much smoother. Advises and useful sources more than welcome.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Character : MonoBehaviour {
private float velocity = 2.0f;
private Vector2 direction;
public void Move() {
transform.Translate(direction * velocity * Time.deltaTime);
}
private void GetInput() {
direction = Vector2.zero;
if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow))
{
direction += Vector2.up;
}
if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
{
direction += Vector2.left;
}
if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow))
{
direction += Vector2.down;
}
if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
{
direction += Vector2.right;
}
}
// Use this for initialization
void Start () {
direction = Vector2.up;
}
// Update is called once per frame
void Update () {
GetInput();
Move();
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612181048im_/https://answers.unity.com/themes/thub/images/avi.jpg)