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 IvanUnity00 · Apr 15, 2013 at 09:42 PM · fpsontriggerenteroncollisionenterconefirstpersonshooter

Cone of effect weapon FPS

I'm looking to make a flashlight weapon for an fps. Basically, I want it to affect a cone in front of the player but only in line of sight. The enemies have weak spots that you have to hit. My idea was to use an invisible cone to detect if anything was inside of it and then use a raycast to see if they were in line of sight. However, I'm running into some problems.

  1. I've found that using onCollisionEnter is only used for rigidbodies and so doesn't seem to apply.

  2. OnTriggerEnter can't be used for moving objects.

My idea then was that when the player pushed the 'fire' button I would instantiate the cone and use OnTriggerEnter to gather up all the objects that intersect with it and then raycast to see is those objects are in line of sight. I just have no idea how to actually do that. Please help.

Comment
Add comment · Show 4
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 Lockstep · Apr 16, 2013 at 01:22 AM 2
Share

You can use Physics.OverlapSphere and check for the angle.

avatar image IvanUnity00 · Apr 16, 2013 at 02:40 AM 0
Share

That looks like exactly what I need, thank you. Now how would I check for the angle?

avatar image Loius · Apr 16, 2013 at 02:53 AM 0
Share

if ( Vector3.Angle( targetPosition - myPosition, myForward ) < flashlightSpread ) TargetInRange();

avatar image IvanUnity00 · Apr 16, 2013 at 02:55 AM 0
Share

Awesome. I just googled it too and found Vector3.Angle. I'm a total noob and this is super helpful. Thank you.

0 Replies

· Add your reply
  • Sort: 

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

14 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

Related Questions

First Person Controller not working with OnCollisionEnter and OnTriggerEnter 1 Answer

OnCollisionEnter vs OnTriggerEnter for performance 1 Answer

Multiple OnTriggerEnter on one script? 2 Answers

Can not get OnTriggerEnter and OnCollisionEnter to work!? 1 Answer

how to make a bullet that'll be like a missile. 2 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