Hello there, I'm trying to convert String to 2DModel. It should seems like that but it should be moved behind the player. I used this model: Code: xxxx xxxx xxx xxx xxx xxx xx xx xx xx xx xx xx xx xx xx xx xx xx x x xx xx x x xx xx xx xx xx xx xx xx xx xxx xxx And this code: PHP: /** * @param string $string * @param float $breakSize * @return Model2D */ public static function convertStringTo2DModel(string $string, float $breakSize = 0.1): Model2D { $lines = explode("\n", $string); /** @var int $minX */ $minX = null; /** @var int $maxX */ $maxX = null; $maxY = 0; foreach ($lines as $line) { $length = strlen($line); if($minX === null) { $minX = $length; } if($maxX === null) { $maxX = $length; } $minX = min($minX, $length); $maxX = max($maxX, $length); $maxY++; } /** @var float $xx */ $xx = ($maxX % 2); /** @var float $yy */ $yy = ($maxY % 2) / 2; /** @var float $centerX */ $centerX = ((int)($maxX-$minX) / 2) + $xx; /** @var Model2D $model */ $model = new Model2D(); $y = 0; while (!empty($lines)) { $last = array_pop($lines); while (strlen($last) < $maxX) { $last = $last . " "; } $spaces = 0; for($i = 0; $i < strlen($last); $i++) { if($i === $centerX) { $model->addPoint(new Vector2(0, $y / 7)); continue; } if($last[$i] === " ") { $spaces++; } if($last[$i] === "x") $model->addPoint(new Vector2(($i < $centerX ? $i - $centerX : $i) / 7, $y / 7)); } $y++; } var_dump($model); return $model; } What did I do wrong? Spoiler: Var_dump output https://hastebin.com/efumixuwul.cs
Fixed, but idk how ._. PHP: /** * @param string $string * @param float $breakSize * * @return Model2D */ public static function convertStringTo2DModel(string $string, float $breakSize = 0.1): Model2D { $lines = explode("\n", $string); var_dump($string); /** @var int $minX */ $minX = null; /** @var int $maxX */ $maxX = null; foreach ($lines as $line) { $length = strlen($line); if($minX === null) { $minX = $length; } if($maxX === null) { $maxX = $length; } $minX = min($minX, $length); $maxX = max($maxX, $length); } /** @var float $centerX */ $centerX = ((int)($maxX-$minX) / 2) + ($maxX % 2); /** @var Model2D $model */ $model = new Model2D(); $y = 0; while (!empty($lines)) { /** @var string $last */ $last = array_pop($lines); while (strlen($last) < $maxX) { $last = $last . " "; } $spaces = 0; for($i = 0; $i < strlen($last); $i++) { if($last[$i] === " ") { $spaces++; } if($last[$i] === "x") { $model->addPoint(new Vector2(($i - (4 * $centerX)) / 7, $y / 7)); } } $y++; } return $model; }