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 Christopher K. · Dec 17, 2010 at 02:42 PM · spritespokemon

2d image representing a 3d object?

I'm trying to emulate the style of the newer Pokemon games where the player and NPC's are 2d sprites in a 3d environment. Right now I have a 3d cube that conforms to an appropriately-sized grid, but what I'd really like is to be able to show a 32x32 image where that cube is instead. Is this possible, and if so, how? OnGUI doesn't seem appropriate to me as at times I'll need to have the GUI appear over this setup.

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 skovacs1 · Dec 17, 2010 at 04:55 PM

Having not played the newer ones, I can't say for certain, but from the videos I've seen of them, it is entirely possible that these pokemon games are actually 2d sprites in an 2d environment made up of pre-rendered 3D sprites. Regardless, your question was how to do 2D sprites in a 3D environment.

You can have multiple GUIs and you can have stuff appear on top of other stuff, but in order to actually be "in" a 3D environment, your object would need to have some depth position in the environment. To do this with an object in the scene, you would essentially map your sprite with alpha to a camera-aligned plane. in the scene. If you want to use GUI sprites, it may as well be a GUITexture GameObject which you can setup in the scene and muck about with.

How you choose to align to the camera depends on the look that wish to achieve. You could simply make the plane always face the camera like:

@script ExecuteInEditMode()
function Update () {
    transform.up = Camera.main.transform.position - transform.position;
    transform.forward = -Camera.main.transform.up;
}

Or you could just assume a camera alignment and fix all your planes relative to this.

A 32x32 image? That's the minimum allowed size for a Unity texture, but it will work just fine. To animate your sprite, you could swap out the image. This is robust because the same code essentially works even for larger sized sprites, etc.

An alternative approach is to choose a larger image size, tiled on the plane to only show one 32x32 block, include the frames of various animations at particular points in the larger texture and then you could animate it by simply changing your texture's offset. With a bit of math at the start, this could work for arbitrarily-sized sprites as well.

Mapping with the alpha is done fairly easily with the standard transparent cut-out shaders. If you don't want them to be affected by lighting, there is also an unlit version of these.

I'm not sure why you were using a cube. If you have multiple perspectives on your sprite, to make that actually look correct, you'd be better off animating (or simply swapping) the sprite for the rotation.

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 Eric5h5 · Dec 17, 2010 at 07:30 PM 0
Share

A Unity texture can be 1x1 if you want; 32x32 isn't the $$anonymous$$imum.

avatar image Christopher K. · Dec 20, 2010 at 01:44 PM 0
Share

1x1? That sounds WAY too hi-res to me. ;)

I was using the cube just so that I could see the object taking up its entire space in the grid, to be honest.

avatar image
1

Answer by JoshOClock · Dec 18, 2010 at 02:51 AM

I had some luck by spawning a prefab with a GUITexture component and moving that using this code in C#:

public Transform GuiHelper;

void Start() { GuiHelper = (Transform)Instantiate(GUIHelperPrefab, Vector3.zero, Quaternion.identity); }

Vector2 GetScreenPos() { Vector2 screenPos = Camera.main.WorldToScreenPoint(transform.position); Vector2 convertedGUIPos = GUIUtility.ScreenToGUIPoint(screenPos);

 return new Vector2(convertedGUIPos.x / Screen.width, convertedGUIPos.y / Screen.height);

}

void OnGUI() { if (GuiHelper) { GuiHelper.transform.position = GetScreenPos(); } }

The 'GUIHelper' is just a prefab I made that contains a GUITexture.

The caveat being that you may run into sorting weirdness if your objects overlap in your playfield. But if their positions are fixed you might be okay.

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

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

No one has followed this question yet.

Related Questions

How to improve performance with 10,000s of GameObjects? 4 Answers

Evenly distributing sprites in an animation 1 Answer

Allow 2D sprite to receive light from any direction and show on both sides 0 Answers

Particle System Z-ordering 0 Answers

Urgent Question, I've already programmed and the problem has just popped up, but as soon I start moving the character it grows HUGE! 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