• 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 Thorn Blackstar · Apr 12, 2012 at 05:44 PM · direction

Figuring out if another boject is to my right or left

Hi, I'm building a 2d fighter and I'm having some trouble figuring out how to check what side each fighter is on. I have a Boolean set for "OnLeft" So when its true, directions on the controllers swap along with materials ect, but I cant figure out the way for the game to detect this. If someone could point me to the relevant documents on the scripting reference it would be helpful

Comment
Add comment · Show 3
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 CHPedersen · Apr 12, 2012 at 05:50 PM 0
Share

I have an idea, but I think I'll need you to please elaborate the scenario a little before I'll write up a reply. I'm not 100% sure I've understood what you're describing correctly:

Is this a 3D space shooter ala Freelancer, and you want to know which side of the screen an enemy aircraft appears on?

Sorry, I just realized that question sounds a little silly when you included the phrase "2D" in your question. >_<

avatar image BiG · Apr 12, 2012 at 06:10 PM 0
Share

I think that he's speaking about a beat 'em up, by the way! Hoping to have understood well... ^_^

avatar image Thorn Blackstar · Apr 12, 2012 at 07:43 PM 0
Share

yeah i should have said fighting game ins$$anonymous$$d of fighter :P

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by BiG · Apr 12, 2012 at 05:51 PM

Well, I suppose that your axis are X (horizontal) and Y (vertical), and your fighters follow the same coordinate system.

In each moment, a fighter has to be turned to the left, and the other has to be turned to the right (because they have to look at each other). Correct? ;)

So, the "1UP" fighter has to start with OnLeft=true, because the controllable player is always in the left side of the screen, at the beginning. The "COM" fighter (controlled by CPU) has, naturally, OnLeft=false.

Then, at every moment, the fighter on the left is the one with the lower x coordinate in its transform! So, you have to perform a test like this:

 if (1P.transform.position.x < COM.transform.position.x)
    //Set 1P's variable to true and COM's variabe to false
 else
    //Set 1P's variable to false and COM's variable to true
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 Thorn Blackstar · Apr 12, 2012 at 07:45 PM 0
Share

thank you, dident think of that at all

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

my rocket fires in the wrong direction 4 Answers

player view Rotation check 0 Answers

The direction of travel is not rotating with the projectile in the spinning GameObject. 5 Answers

NPC Transform.Direction relative to player?? 0 Answers

Child object using Origin (0, 0, 0) as its forward direction 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