There’s a bug in one of my games called A.I Test: Top-Down where diagonally moving non-walkable tiles in the 4th map the player can access will move in a gradually shrinking range and when they stop moving, they drift off. If you want to see the bug, go to A.I Test: Top-Down by CreeperExplodeMakesGames1, download V1.1, and press N until you go to the 4th map. Here’s the code for the moving tiles.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MovingTile : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
x = transform.position.x;
y = transform.position.y;
}
// Update is called once per frame
void Update()
{
transform.position = new Vector2(x + xoffset, y + yoffset);
if (xchanging)
{
if (increasing)
{
if (reversed)
{
xoffset -= Time.deltaTime;
}
else
{
xoffset += Time.deltaTime;
}
}
else
{
if (reversed)
{
xoffset += Time.deltaTime;
}
else
{
xoffset -= Time.deltaTime;
}
}
if (xoffset <= 0f & !reversed | xoffset >= 0f & reversed)
{
increasing = true;
}
else if (xoffset >= 1f & !reversed | xoffset <= -1f & reversed)
{
increasing = false;
}
}
if (ychanging)
{
if (increasing)
{
if (reversed)
{
yoffset -= Time.deltaTime;
}
else
{
yoffset += Time.deltaTime;
}
}
else
{
if (reversed)
{
yoffset += Time.deltaTime;
}
else
{
yoffset -= Time.deltaTime;
}
}
if (yoffset <= 0f & !reversed | yoffset >= 0f & reversed)
{
increasing = true;
}
else if (yoffset >= 1f & !reversed | yoffset <= -1f & reversed)
{
increasing = false;
}
}
}
private float x;
private float y;
private float xoffset;
private float yoffset;
public bool xchanging;
public bool ychanging;
public bool reversed;
private bool increasing;
}