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 SystemIsGod · Apr 18, 2013 at 12:10 AM · androidmobilecrosshair

Crosshair possible with mobile flying game?

I've been looking around quite a bit, thinking and trying things and I want to have it to follow the yaw of the ship, or the direction it's facing but it seems impossible right now. I am using nGui, however if I have to use unity gui I suppose that is okay because it is something simple. I've tried attaching items as children to the ship but nothing seems to be working. I'm just not sure where to start, if you have any information thank you.

Comment
Add comment · Show 2
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 · Apr 18, 2013 at 02:31 AM 0
Share

I have only a vague idea of your problem from your question. You need to add a lot more information...maybe an images as well. Is the plane first or third person? How do you want the crosshair to track the plane? Why did making the crosshair a child not work? Do you want to the crosshair in world space or some other space? What is the relationship between the crosshair and any projectiles fired. And so on.

avatar image SystemIsGod · Apr 18, 2013 at 03:31 AM 0
Share

Sorry I wasn't clear as I should have been. Basically what I have right now is a plane, or space ship that's fully moving and working with shooting missiles from the front of it. So if I am moving left the missiles will shoot out left. All I need is a crosshair that follows the direction of the ship, so if it is turning left a little, the cross hair will be moved left a little so it's more accurate if they were to shoot a missile. Does this help at all?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · Apr 18, 2013 at 04:13 AM

It is still fairly fuzzy, but I'm going to make some guesses. Let's assume you have a 3-person plane with a camera following the plane. Step one is figure out a hit distance in 3D space. This could be a a fixed distance of travel for the missiles or it could be a position of a target. Let assume the first. Construct a ray from the missile in the direction of travel. Then calculate the world position of the hit. Finally transform the world position into a position to display the crosshair. In the code below, I transform it into screen coordinates for use with GUI. I don't know NGUI.

 var ray = new Ray(missile.transform.position, missile.transform.forward);
 var world_pos = ray.GetPoint(hit_distance);
 var screen_pos = Camera.main.WorldToScreenPoint(world_pos);
Comment
Add comment · Show 3 · 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 robertbu · Apr 18, 2013 at 04:20 AM 0
Share

Frogot to mention that if you are using gravity, the missile will drop a bit between firing and when it reaches the 'hit_distance.' With a fixed distance, you can just subtract some from world_pos before making the final conversion to compensate.

avatar image SystemIsGod · Apr 18, 2013 at 05:17 AM 0
Share

Oh goodness that was more than I expected it to be, does this have a big hit on performance? I should note this would be for a mobile game as I said in the title, also everything is working in the game, I just wanted the crosshair to help someone while shooting.

The missile fires and does everything just fine, it's just difficult to aim. It's rather simple so I'm surprised about the ray casting etc, but you know more than I do, clearly.

avatar image robertbu · Apr 18, 2013 at 01:53 PM 0
Share

This is not a raycast. It is just using a ray to fine a point in 3D space. You should not see a performance hit.

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

11 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

Related Questions

iOS and Android Publishing 2 Answers

Shadows problem with mobile. 1 Answer

Is this surface shader too heavy for mobile? 0 Answers

Asset Bundles compatibility for mobile 1 Answer

Question about Multithreaded rendering! 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