• 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
2
Question by stubbornmoose · Dec 11, 2009 at 05:06 PM · iphoneoptimization

Colliders vs RayCast (automatic crosshair aiming in an FPS game)

Colliders vs RayCast

I have to implements automatic crosshair aiming in my FPS game. What is the best (performing on iPhone) solution for that?

I can see two options here:

1: Using Triggers:

Ex: Adding an additional collider to the player object in shape of a long stick, potentially long sphere) and a rigid body marked as kinematic Detecting OnTriggerEnter/Exit between player and enemy colliders. After that use a linecast and if there are no objects on the way moving crosshair based on enemy position.

2: Using RayCasting:

Ex. Use couple (at least three) raycasts in a direction coming from camera, detect object on their way using Physics.Raycast Once enemy has been detected move crosshair based on its position.

So, what is the most expensive operation? Using rigidbody with OnTriggerEnter/Leave handling with one LineCast or 3 raycasts (with additional layer)?

Thanks

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

1 Reply

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

Answer by Lucas Meijer 1 · Dec 11, 2009 at 07:52 PM

If your goal is to aim your crosshair at the closest enemy, if that guy is close enough, you could solve it much simpler, by using Camera.WorldSpaceToScreenSpace() and getting the screencoordinates of this guy. If it's close enough to the middle of your screen, you can rotate the camera/crosshair more towards the guy.

Doing triggers and raycasts seems like very performance heavy operations that don't actually get you want you want.

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 Jean-Fabre · Dec 27, 2010 at 12:24 PM 0
Share

fair enough, but I am wondering the same question but without any screen interaction, so what is actually faster? raycast or trigger?

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

help with iphone 3GS performance (polys and audio) 2 Answers

Large level loading best practices 1 Answer

iOS lag(slow-mo) 1 Answer

Collider Physics Optimization 1 Answer

How can I list used assets on Unity Pro - iPhone Pro 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