Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by LMan · Mar 20, 2014 at 05:46 PM · spritetexture2dcoordinatesanchormodular

How to define a point on a sprite, and get that point in world space.

What I want is to be able to define a series of points on a sprite that can function as an anchor for modular pieces- like if I have several heads, hairs, eyes, nose, lips, ect.. If I could define a point on the head sprite where the eye would go, and then another point on the eye sprite where I wanted it to attach, I could just position the eye so that it's anchor lines up with the "eye socket" anchor point on the head. Can anybody point me in the right direction? Thanks!!

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

1 Reply

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

Answer by Dblfstr · Mar 20, 2014 at 06:46 PM

Yep, for every item that you want to place (i.e. eye, nose, lips, etc) Create an empty gameobject at that location. For instance create an empty gameobject and position it at the eye socket. Name this gameobject "eyeLocation" or "eyeLocationLeft" or something like that.

Now, how you decide to apply the eye in this location will differ, adn can be done many ways. One way, is to have a script with an array of sprites Eye[]. Then, depending on what eye is chose, set the gameobjects Spriterenderer.sprite to Eye[1], or whichever eye index you desire.

Comment
Add comment · Show 5 · 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 LMan · Mar 20, 2014 at 08:06 PM 0
Share

There's no way of doing this that doesn't involve having to go through every sprite in every spritesheet and making a prefab out of it?

avatar image Dblfstr · Mar 20, 2014 at 09:10 PM 0
Share

You want 'anchor points' on a sprite, that you would setup yourself. Well, these 'anchor points' are empty gameobjects. The gameobject simply defines a point in space. What you want to do at that particular point is up to you. I mean, I guess your head sprite (or any sprite which would have other sprites attached) would be a prefab combined with the gameObject anchors.

There are always paid assets like 2D Sprite kit, that may assist you.

However, for items that will not have other items attached, there is no need for a prefab. Also, you can change the pivot point of each sprite in the sprite editor. If you have a sprite sheet of multiple sprites, the little blue circle at the center of each sprite is movable, and is the pivot point (relative 0,0).

avatar image Dblfstr · Mar 20, 2014 at 09:12 PM 0
Share

Can I ask the purpose of this functionality? Is if for creating an avatar for a player, or customizing a player. I am picturing $$anonymous$$r. Potato Head as I type...

avatar image LMan · Mar 21, 2014 at 05:39 PM 0
Share

sure- I'm working on a tool that procedurally generates assets given modular pieces from a spritesheet. $$anonymous$$r. potato head isn't really far off! The idea is to take a lot of busywork out of making varied characters/items/weapons/whatever. The issue is that when I swap out sprites that are different sizes and shapes from each other, they aren't positioned quite right anymore. (see before and after pics below.) So I need some kind of data that will give me a reference point to where things are supposed to match up. But it's not preferable to ask the user to go through and prepare every sprite with gameobjects in order to keep that info. I'm now thinking that I'll make a class that both stores the sprite, and an array of Vector2s that keep points on the sprite.rect, then somehow get those points in world space. The thing is, I'd have to rig up a way of visually representing those points in some sort of preview window or something. It's a lot of work, but I guess it is what it is. I am more than open to suggestions on better ways to do this- I have a tendency to over-complicate things. alt text alt text

positioning issue3.png (24.3 kB)
positioning issue1.png (22.4 kB)
avatar image Dblfstr · Mar 21, 2014 at 05:53 PM 0
Share

Pics aren't showing up for me right now. But, are these going to be all your own sprites? or allow users to use whatever sprites they want? If they are all yours, it will be easier, since you can predefine everything you need. Otherwise, I don't know how you would achieve this (without the user having to set the reference points themselves. That, my friend, is way above my level. :D

Edit: Pics are showing.

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

21 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 avatar image avatar image avatar image

Related Questions

Resize a sprite by giving it more transparent pixels 0 Answers

My sprite from sprite.create looks pixelated. 1 Answer

Change Color Based On Pixel X Coordinate in Shader 1 Answer

Struggling to find how to access the Texture 2D of a sprite. 1 Answer

How do I access a texture slice's rect via scripting? 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