- Home /
Level is not at 0, 0, 0 after setting the coordinates to 0, 0, 0?
I made this script for the level object and set the coordinates to 0, 0, 0:
using UnityEngine; using System.Collections;
public class Levels : MonoBehaviour {
private int levelWidth;
private int levelHeight;
public Transform NcolWoodOneTile;
public Transform NcolGrassOneTile;
private Color[] tileColors;
public Color NcolWoodOneColor;
public Color NcolGrassOneColor;
public Texture2D levelTexture;
public float tileSideLength = 0.16f;
// Use this for initialization
void Start () {
levelWidth = levelTexture.width;
levelHeight = levelTexture.height;
loadLevel ();
}
// Update is called once per frame
void Update () {
}
void loadLevel () {
tileColors = new Color[levelWidth * levelHeight];
tileColors = levelTexture.GetPixels ();
for(int y = 0; y < levelHeight; y++)
{
for(int x = 0; x < levelWidth; x++)
{
if(tileColors[x+y*levelWidth] == NcolWoodOneColor)
{
Instantiate(NcolWoodOneTile, new Vector2(x, y) * tileSideLength, Quaternion.identity);
}
if(tileColors[x+y*levelWidth] == NcolGrassOneColor)
{
Instantiate(NcolGrassOneTile, new Vector2(x, y) * tileSideLength, Quaternion.identity);
}
}
}
}
}
When you look in the position boxes at the full number are they to the power of(you will see some weird looking stuff at the end of the number if they are). If so then the placement variation from (0,0,0) is $$anonymous$$ute and it is to do with floating point in-precision.
PS notice the number is not zero for the player position. but when the player is at the lower left corner i want him to be at 0, 0, 0
Have a look at float rounding, this should sort it out :
http://docs.unity3d.com/ScriptReference/$$anonymous$$athf.Round.html
I dont understand this lol is it something I did in the components?
Answer by Jeff-Kesselman · Nov 11, 2014 at 11:43 PM
That looks like object 0,0 to me.
I don't do any Unity 2D but I assume the coordinate space is the same and origin by default is typically screen center.
Edit: Yup just did a quick test. By default (0,0) is screen center in a unity 2D project.
If this seems odd to you, its because Unity2D is not really a 2D game engine in the classic sense. Its a 3D game engine running with an orthogonal view. As such its not bound to screen pixels.
Edit addl: Read this. Unity 2D screen coordinates are based on the orthographic projection in use and the camera position.
Your character is basically at pos (0,0). Your character is probably offset from where you want it because your character is placed via his center(this is his anchor point). So you need to offset his position by half his height in +y direction and half his width in the +x direction. So that his left foot is at pos (0,0). Does this make sense awplays49 ?
I mean the map i made with a texture is offset not the character its offset by like 0.5 y and .2 x
Your answer
![](https://koobas.hobune.stream/wayback/20220613171303im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Translate World transform data to UV offset 2 Answers
open door to next level, after 10000 points were added to your score (solved) 2 Answers
Spawn Player when Room Starts - (Multiplayer) 1 Answer
How do you add levels to your game? 1 Answer
UnityGUI controls stay on the screen after level load 0 Answers