I’m sure this is an incredibly novice question, but I’ve looked all over online and can’t seem to figure out what’s going on. I’ve got a very basic 2D, top-down scene with two sprites - a PC and an NPC, and they’re set up with basic controllers that move them when an arrow key is pressed (up / down / left / right). That’s all working fine, except that when the sprite is transformed to its new location, the image remains in the old location, creating what looks like a classic “snake” game (see image).
I’m sure this is something simple that I’m missing but after spending an hour watching tutorials and reading answers online, I can’t for the life of me figure out what setting or command I’m missing.
Here’s the knight’s Update() script, if this helps (the means of transform is probably overdone, but I couldn’t get the tutorial examples to work because of an ambiguity error using transform.position += Vector2.left * dSpeed.
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.LeftArrow))
{
Vector2 v2 = new Vector2();
v2 = transform.position;
v2 += (Vector2.left * dSpeed);
transform.position = v2;
}
if (Input.GetKeyDown(KeyCode.RightArrow))
{
Vector2 v2 = new Vector2();
v2 = transform.position;
v2 += (Vector2.right * dSpeed);
transform.position = v2;
}
if (Input.GetKeyDown(KeyCode.UpArrow))
{
Vector2 v2 = new Vector2();
v2 = transform.position;
v2 += (Vector2.up * dSpeed);
transform.position = v2;
}
if (Input.GetKeyDown(KeyCode.DownArrow))
{
Vector2 v2 = new Vector2();
v2 = transform.position;
v2 += (Vector2.down * dSpeed);
transform.position = v2;
}
}
And here’s the sprite settings for the knight: