Hello! I would need a script that can move the character up, down, right, left (in 2D) so that it slides further and doesn’t stop. Thanks in advance for the comments. ![]()
Maybe try using rigidbody.Addforce and a low friction on the surface with a physics material?
this is a script that gives the object a steady speed:
GameObject player;
public float speed;
Vector2 direction;
// Start is called before the first frame update
void Start()
{
player = GameObject.Find("Player");
}
// Update is called once per frame
void Update()
{
if(direction.y != 0)
{
player.transform.Translate(0, speed * Time.deltaTime * direction.y, 0);
}
if(direction.x != 0)
{
player.transform.Translate(speed * Time.deltaTime * direction.x, 0, 0);
}
if (Input.GetKey(KeyCode.UpArrow))
{
direction.y = 1;
direction.x = 0;
}
if (Input.GetKey(KeyCode.DownArrow))
{
direction.y = -1;
direction.x = 0;
}
if (Input.GetKey(KeyCode.LeftArrow))
{
direction.y = 0;
direction.x = -1;
}
if (Input.GetKey(KeyCode.RightArrow))
{
direction.y = 0;
direction.x = 1;
}
}