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 /
This question was closed Sep 29, 2013 at 06:10 AM by robertbu for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by williampigmeu · Sep 29, 2013 at 05:07 AM · transformspritemodelanglebillboard

Doom-like Sprite Models

Im currently with a project in development, an old-school doom-like fps, atm I'm using billboard shaders to render the enemies and objects, planes for the floor, ceiling and walls and cubes for objects (doors, buttons). The Doom's billboards have 7 images, each for an angle, what I need is: Check the angle relative to the player's current position.

Comment
Add comment · Show 10
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 robertbu · Sep 29, 2013 at 05:11 AM 1
Share

You need to explain a bit more. Are you looking for the angle between the sprite and the player? What are you using to display the sprites (Plane, Quad, Custom Plane...)? How are you going to use this angle?

avatar image williampigmeu · Sep 29, 2013 at 05:18 AM 0
Share

I'm using a textured Plane with a billboard shaded material. I need to know the angle between the player and the plane current rotation, to change it's sprite to the right one.

EDIT: http://www.youtube.com/watch?v=yr-lQZzevwA, the "3d models" are actually sprites, theres one sprite for each angle, and there are 7 angles, each adding 45°.

avatar image robertbu · Sep 29, 2013 at 05:27 AM 1
Share

If you are using Plane such as created by Game Object>Create Other>Plane, then the visible surface is Up. You can get the angle using Vector3.Angle(player.transform.forward, plane.transform.forward.up). A cube has six sides/angles. What are the seven angles used by Doom?

avatar image williampigmeu · Sep 29, 2013 at 05:30 AM 0
Share

You can see what I need there: http://www.doomlegends.com/emporium/tutorials/sprite_basics.html

avatar image clunk47 · Sep 29, 2013 at 05:37 AM 1
Share

Have a look here: http://wiki.unity3d.com/index.php?title=CameraFacingBillboard

avatar image williampigmeu clunk47 · Sep 29, 2013 at 05:38 AM 0
Share

I already got the billboard working, I just need to change the sprite according to the his angle relative to the player's view.

avatar image clunk47 clunk47 · Sep 29, 2013 at 05:42 AM 1
Share

What do you mean, change the texture?? Please be more specific on what you mean by "Change the sprite".

avatar image williampigmeu clunk47 · Sep 29, 2013 at 05:45 AM 0
Share

Change the texture.

Show more comments

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by robertbu · Sep 29, 2013 at 06:08 AM

Good reference. I can think of a few ways. Mathf.Atan2() will likely be the most efficient. First, you get a vector from the object to the player. Assuming each object is controlling its own texture it would be something like:

 var dir = player.position - transform.position;  
 var angle = Mathf.Atan2(dir.z, dir.x);
 if (angle < 0.0)
     angle = angle + 360.0;
 var index = Mathf.RoundToInt(angle / 45.0); 
  

Note this is the angle on the XZ plane and disregards the 'y' component. I believe this is what you want. Also the index will go from 0 to 7 and, even if incremented by 1, the numbers will not line up with the number in the diagram. I think that 0 will line up with 7 and the numbers will increase counter clockwise, but you'll have to play and see.

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 BDX777 · Jan 25, 2015 at 02:52 PM 0
Share

You should have added $$anonymous$$athf.Rad2Deg;

 Vector3 direction = Camera.main.transform.position - characterAIAgent.transform.position;
         float angle = $$anonymous$$athf.Atan2(direction.z, direction.x) * $$anonymous$$athf.Rad2Deg;
 
         if(angle<0.0f)
         {
             angle+=360.0f;
         }
 
         int index = $$anonymous$$athf.RoundToInt(angle / 45.0f);


Doing this gave me those two missing indexes, I tried using your method and I had to modify it in order to get more than 0 and 8 indexes.

By the way Doom actually uses 8 angles, OP.

avatar image BDX777 · Jan 25, 2015 at 03:25 PM 0
Share

Also you would need to take the object's rotation into account, not just the position.

Follow this Question

Answers Answers and Comments

16 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

Related Questions

Animating Sprites 1 Answer

Sprite doesn't flip correctly. 1 Answer

Imported model gives error: "Transform.rotation is no longer valid" 2 Answers

Obtaining the relative size of a Models body part 1 Answer

Problems caused by non-unique Euler angle solutions 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