• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by awplays49 · Nov 11, 2014 at 11:42 PM · levelcoordinatesoffset

Level is not at 0, 0, 0 after setting the coordinates to 0, 0, 0?

alt text

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);
             }
         }
     }
 }

}

screenshot (77).png (143.4 kB)
Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MrSoad · Nov 11, 2014 at 10:54 PM 0
Share

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.

avatar image awplays49 · Nov 11, 2014 at 10:59 PM 0
Share

Im confused how do i fix it?

avatar image awplays49 · Nov 11, 2014 at 11:02 PM 0
Share

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

avatar image MrSoad · Nov 11, 2014 at 11:08 PM 0
Share

Have a look at float rounding, this should sort it out :

http://docs.unity3d.com/ScriptReference/$$anonymous$$athf.Round.html

avatar image awplays49 · Nov 11, 2014 at 11:12 PM 0
Share

I dont understand this lol is it something I did in the components?

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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.

http://stackoverflow.com/questions/22594074/unity-4-3-understanding-positions-and-screen-resolution-how-to-properly-set-p

Comment
Add comment · Show 31 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image awplays49 · Nov 11, 2014 at 11:46 PM 0
Share

What are you saying?

avatar image awplays49 · Nov 11, 2014 at 11:55 PM 0
Share

So fix to make the center of the grid at 0, 0?

avatar image awplays49 · Nov 11, 2014 at 11:55 PM 0
Share

how do i ^^^

avatar image MrSoad · Nov 12, 2014 at 12:01 AM 0
Share

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 ?

avatar image awplays49 · Nov 12, 2014 at 12:03 AM 0
Share

I mean the map i made with a texture is offset not the character its offset by like 0.5 y and .2 x

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Translate World transform data to UV offset 2 Answers

PlayerPrefs Problem crashing with SetBool 2 Answers

Post-Build Custom Level Loading 2 Answers

Making the floor/ground of a map 1 Answer

Chage level Whith time 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges