Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 POLYGAMe · Aug 27, 2011 at 11:45 PM · 2dspritestexturessplit screen

Changing texture depending on angle to another player

Hi there,

I'm working on a retro "pseudo 3D" game (think original Doom) and it has two play screens, one for each player.

I have worked out how to make each player appear properly in the other player's screen by making sure it always faces the other player's camera (billboard style), so that it doesn't rotate into nothingness...lol.

My question is, I need to change the texture, depending on the angle of the character that the player is looking at. For example... if P1 is in front of P2 and facing away, I want to draw the back texture sprite for P1, and if P1 is facing P2, draw the front. I also have sprites for side on and 45 degree angles (8 sprites in all).

What's the best way to do this? As players can move in 3 dimensions and rotate, it's a bit of a tricky one for a noob like me...

Any help greatly appreciated ;-)

Comment
Add comment · Show 1
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 POLYGAMe · Aug 27, 2011 at 11:50 PM 0
Share

I should add, I can code... not asking for a complete script here... just the best method... I do SUC$$anonymous$$ at math!!! lol. Any pseudo-code, ideas welcome :)

1 Reply

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

Answer by ckfinite · Aug 28, 2011 at 01:23 AM

Well, the high-level idea is this: get the direction vector, use ArcTangent to find the angle to the the other player, then fetch the correct sprite. Example (C#) code (WARNING: completely untested):

 Vector3 direction_vector = player1.transform.position - player2.transform.position;
 float angle = Mathf.Atan2(direction_vector.x,direction_vector.z) * Mathf.Rad2Deg;
 if (angle > 0 && angle <= 90)
     DrawRightSprite();
 else if (angle > 90 && angle <= 180)
     DrawBackSprite();
 //etc...
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 POLYGAMe · Aug 28, 2011 at 01:50 AM 0
Share

Awesome, thanks a lot! Should be able to make that work ;-)

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

What is the best way of creating a modular texture? 0 Answers

Is there any benefit to slicing in power of two dimensions inside a sprite sheet? 1 Answer

Unity 2D and Texture Memory. 1 Answer

2D Layout + 2D Spritesheets 0 Answers

How to drag and stretch a 2D sprite 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