void FixedUpdate() { if ( !mover.moving ) return; // If not moving, nothing to do here int facing = mover.GetFacing(); // If we are moving in a direction, align to the grid // First, get the grid location Vector2 rPos = mover.roomPos; Vector2 rPosGrid = mover.GetRoomPosOnGrid(); // This relies on IFacingMover (which uses InRoom) to choose grid spacing // Then move towards the grid line float delta = 0; if (facing == 0 || facing == 2) { // Horizontal movement, align to y grid delta = rPosGrid.y - rPos.y; } else { // Vertical movement, align to x grid delta = rPosGrid.x - rPos.x; } if (delta == 0) return; // Already aligned to the grid float move = mover.GetSpeed() * Time.fixedDeltaTime; move = Mathf.Min( move, Mathf.Abs(delta) ); if (delta < 0) move = - move; if (facing == 0 || facing == 2) { // Horizontal movement, align to y grid rPos.y += move; } else { // Vertical movement, align to x grid rPos.x += move; } mover.roomPos = rPos; }
private void FixedUpdate() { if (!mover.moving) { return; // If not moving, nothing to do here } int facing = mover.GetFacing(); // If we are moving in a direction, align to the grid // First, get the grid location Vector2 rPos = mover.roomPos; Vector2 rPosGrid = mover.GetRoomPosOnGrid(); // This relies on IFacingMover (which uses InRoom) to choose grid spacing // Then move towards the grid line float delta = 0; if (facing == 0 || facing == 2) { // Horizontal movement, align to y grid delta = rPosGrid.y - rPos.y; } else { // Vertical movement, align to x grid delta = rPosGrid.x - rPos.x; } if (delta == 0) { return; // Already aligned to the grid } float move = mover.GetSpeed() * Time.fixedDeltaTime; move = Mathf.Min(move, Mathf.Abs(delta)); if (delta < 0) { move = -move; } if (facing == 0 || facing == 2) { // Horizontal movement, align to y grid rPos.y += move; } else { // Vertical movement, align to x grid rPos.x += move; } mover.roomPos = rPos; }
void FixedUpdate() { if (!mover.moving) { return; } // If not moving, nothing to do here int facing = mover.GetFacing(); // If we are moving in a direction, align to the grid // First, get the grid location Vector2 rPos = mover.roomPos; Vector2 rPosGrid = mover.GetRoomPosOnGrid(); // This relies on IFacingMover (which uses InRoom) to choose grid spacing // Then move towards the grid line float delta = 0; if (facing == 0 || facing == 2) { // Horizontal movement, align to y grid delta = rPosGrid.y - rPos.y; } else { // Vertical movement, align to x grid delta = rPosGrid.x - rPos.x; } if (delta == 0) { return; // Already aligned to the grid } float move = mover.GetSpeed() * Time.fixedDeltaTime; move = Mathf.Min(move, Mathf.Abs(delta)); if (delta < 0) { move = -move; } if (facing == 0 || facing == 2) { // Horizontal movement, align to y grid rPos.y += move; } else { // Vertical movement, align to x grid rPos.x += move; } mover.roomPos = rPos; }
private void FixedUpdate() { if (!_mover.Moving) { return; // Если объект не перемещается, выйти } var facing = _mover.GetFacing(); // Если объект перемещается, применить выравнивание по сетке // Cначала получить координаты ближайшего узла сетки Vector2 rPos = _mover.RoomPos; Vector2 rPosGrid = _mover.GetRoomPosOnGrid(); // Этот код полагается на интерфейс который использует InRoom для определения шага сетки // Затем подвинуть объект в сторону линии сетки float delta = 0; if (facing == 0 || facing == 2) { // Движени по горизонатали, выравнивание по оси y delta = rPosGrid.y - rPos.y; } else { // Движение по вертикали, выравнивание по оси х delta = rPosGrid.x - rPos.x; } if (delta == 0) { return; // Объект уже выровнен по сетке } var move = _mover.GetSpeed() * Time.fixedDeltaTime; move = Mathf.Min(move, Mathf.Abs(delta)); if (delta < 0) { move = -move; } if (facing == 0 || facing == 2) { // Движени по горизонатали, выравнивание по оси y rPos.y += move; } else { // Движение по вертикали, выравнивание по оси х rPos.x += move; } _mover.RoomPos = rPos; }
private void FixedUpdate() { if (!mover.moving) { return; } int facing = mover.GetFacing(); Vector2 rPos = mover.roomPos; Vector2 rPosGrid = mover.GetRoomPosOnGrid(); float delta = 0; if (facing == 0 || facing == 2) { delta = rPosGrid.y - rPos.y; } else { delta = rPosGrid.x - rPos.x; } if (delta == 0) { return; } float move = mover.GetSpeed() * Time.fixedDeltaTime; move = Mathf.Min(move, Mathf.Abs(delta)); if (delta < 0) { move = -move; } if (facing == 0 || facing == 2) { rPos.y += move; } else { rPos.x += move; } mover.roomPos = rPos; }
private void FixedUpdate() { if (!mover.moving) { return; //if not moving then do nothing } int facing = mover.GetFacing(); //if moving in a direction then align to grid Vector2 rPos = mover.roomPos; Vector2 rPosGrid = mover.GetRoomPosOnGrid(); //then move towards grid line float delta = 0; if (facing == 0 || facing == 2) { delta = rPosGrid.y - rPos.y; } else { delta = rPosGrid.x - rPos.x; } if (delta == 0) { return; } float move = mover.GetSpeed() * Time.fixedDeltaTime; move = Mathf.Min(move, Mathf.Abs(delta)); if (delta < 0) { move = -move; } if (facing == 0 || facing == 2) { rPos.y += move; } else { rPos.x += move; } mover.roomPos = rPos; }
private void FixedUpdate() { // Если объект не перемещается - выйти if (!mover.Moving) { return; } int facing = mover.GetFacing(); // Если объект перемещается, применить выравнивание по сетке // Сначала получить координаты ближайшего узла сетки Vector2 rPos = mover.RoomPos; Vector2 rPosGrid = mover.GetRoomPosOnGrid(); // Этот код полагается на интерфейс IFacingMover для определения шага сетки // Подвинуь объект в сторону линии сетки float delta = 0; if (facing == 0 || facing == 2) // Движение по горизонтали, выравнивание по оси у { delta = rPosGrid.y - rPos.y; } else // Движение по вертикали, выравнивание по оси х { delta = rPosGrid.x - rPos.x; } if (delta == 0) { return; // Объект уже выровнен по сетке } float move = mover.GetSpeed() * Time.fixedDeltaTime; move = Mathf.Min(move, Mathf.Abs(delta)); if (delta < 0) { move = -move; } if (facing == 0 || facing == 2) { rPos.y += move; } else { rPos.x += move; } mover.RoomPos = rPos; }
private void FixedUpdate() { if (!mover.moving) { return; } int facing = mover.GetFacing(); // если объект перемещается, применить выравнивание по сетке, получив координаты ближайшего узла Vector2 rPos = mover.roomPos; Vector2 rPosGrid = mover.GetRoomPosOnGrid(); // этот код полагается на IFacingMover для определения шага сетки // двигаем объект в сторону линии сетки float delta = 0; if (facing == 0 || facing == 2) { delta = rPosGrid.y - rPos.y; // горизонтальное движение, выравнивание по у } else { delta = rPosGrid.x - rPos.x; // вертикальное движение, выравнивание по х } if (delta == 0) { return; // объект уже выровнен } float move = mover.GetSpeed() * Time.fixedDeltaTime; move = Mathf.Min(move, Mathf.Abs(delta)); if (delta < 0) { move = -move; } if (facing == 0 || facing == 2) { rPos.y += move; // горизонтальное движение, выравнивание по у } else { rPos.x += move; // вертикальное движение, выравнивание по х } mover.roomPos = rPos; }