Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • 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
1
Question by MD_Reptile · Sep 10, 2013 at 05:18 PM · texture2dgetpixel

Getting inverted Y axis from Texture2D.GetPixel()

This questions complete source code/project is located in this thread:

http://forum.unity3d.com/threads/198919-Destructible-Pixel-Terrain-Open-Source

and my question is this:

I try to do a method to get whether or not the alpha of a certain pixel is 0 or 1. when I do this thought I check for pixels that are from top left of the level. This ends up being around the place it spawns in the player (100, 100 if top left is 0, 0) and when I run those x y through texture2d.getpixel(x, y) it ends up giving me the pixels in the bottom left corner of the texture, however I need the pixels from top left...

It must be something simple like a line of some math to get it working, how could I get my Y to be on my player (which gives its location apparently from top left rather than bottom right... so the very top left would be 0, 0...) and remember that x works its directly below the player (who is near top left corner at spawn, see that thread)

anybody had this problem? I feel like its stupid simple... lol

Here is an image to describe my problem better:

alt text

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by PAEvenson · Sep 10, 2013 at 05:39 PM

Yea, I think texture2d.GetPixel's (0,0) is bottom left of the texture. To get the pixel from top left you could use:

 texture2d.GetPixel(x, texture2d.height - y);


Maybe?

Comment
Add comment · Show 2 · 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 MD_Reptile · Sep 10, 2013 at 05:49 PM 0
Share

Hmm maybe, but the code provides so many other problems its hard to tell haha, I think this is right though! I knew it would be a one-liner :D

I'll mess with it more and if this is right I will accept your answer. EDIT: yes this works for me, thank alot!

avatar image sonolil · Apr 12, 2021 at 03:37 AM 0
Share

Just... why

avatar image
0

Answer by Benjames · Jul 14, 2014 at 01:44 AM

This should be in the coding reference or at least more well known. It killed me for hours spread out over a couple days, while I was trying to retrieve coordinates for full red pixels.

It was pretty ridiculous for something that can be so simply relayed.

Comment
Add comment · Show 1 · 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 MD_Reptile · Jul 14, 2014 at 05:35 AM 0
Share

Yes it could use mention on the docs. Had me busy a couple days anyway. Your answer should be converted to a comment though :p

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.

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

GetPixel optimisation 2 Answers

Find a colour in a Texture2D 1 Answer

Get set of Pixels from PolygonCollider2d Position 0 Answers

Steps in Texture2D after writing values to an array 1 Answer

Unity crashes trying to get pixels and using Debug.Log 0 Answers


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