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
1
Question by fernandovt · Sep 05, 2012 at 06:52 AM · collidertriggerenemysoundflashlight

Problem with Flashlight in Horror Game

I am making a horror game, its in first person, and I have a Flashlight working. The thing is that I wanted that if i'm in the dark, and I point the light of my flashlight to a "monster", a loud sound gets activated, just with the contact of the light with the enemy. I was solving the problem for this common horror movie/game effect for a while and the best that I have right now is a cone atached to the first person view, with the form of the projected light of my flashlight, that works as a Trigger for the sound effect. 1)The problem is that the cone it's not having the same movement of the light that the flashlight projects... I think just the small side of the cone should be attached to the camera, to create some sort of rotation movement from this poin. Does anyone know a way to attach the cone to the camera so it does the same movement as the light? 2) The second problem is the Script, it work with a tag, so when the tag enemy collides with this trigger, a sound will be played. By far, it's not working when its attached to the camera...But I tested it tagging my player as "enemy" and it does work, only that it's a stationary cone on the air, and not the "moving with the light" cone that I need.

Here it's an image I did to explain the idea: alt text

-THE SCRIPT (It gets attached to the cone, with a mesh collider integrated, and the option "IsTrigger" and "Convex" activated. The cone its attached to the main camera, and it must have the form of the light projected from the flashlight. The enemy its a capsule, with capsule collider, with the trigger option desactivated):

 var Sound : AudioClip;
 function OnTriggerEnter(item : Collider)
     {
     if(item.tag == "Enemy")
         audio.PlayOneShot(Sound);
     }

I hope there are some ideas to make this work, it would be a really good contribution to anyone on this comunity who wants to make a horror game;)

idea juego foto.png (230.7 kB)
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 Fattie · Sep 05, 2012 at 08:20 AM 2
Share

superb diagrams !

avatar image You! · Jan 12, 2013 at 03:26 AM 0
Share

Ditto @Fattie

Do you have the conical trigger as a child of the 1st person camera/character/flashlight? That should clear up the problems with the cone not following the character...unless you've applied the trigger mesh to the camera; then it should move with the camera, creating a strange situation.

Secondly, the script for the audio needs to be attached to the trigger object, not the camera (unless the trigger object is the camera, as stated above, which would mean that the script would belong on the camera). Trigger scripts should always go onto the object with the trigger object or the object entering the trigger.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by GameTech · Jan 12, 2013 at 05:04 AM

  1. Make a cone shaped GameObject and an empty GameObject. Use Vertex snapping (while you have move tool on, hold v) to snap the empty game object to the tip of the cone. Now parent the empty GameObject to the cone and the flashlight to the empty GameObject. Reset the GameObject's transform or set everything to 0 while keeping scale to 1. You can then rotate the empty GameObject to match the angle the flashlight points from the pivot. It should then point in the direction your flashlight is looking.

  2. Give a mesh collider to your cone and check isTrigger. Attach a rigidbody to your cone and uncheck gravity. It should now trigger when it hits another collider.

Comment
Add comment · 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
0

Answer by saggarwal1989 · Oct 17, 2013 at 07:26 PM

Parent your cone to the spotlight you are using. It will follow the spotlight the way you want it to.

Comment
Add comment · 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

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

Restart sound when re-entering trigger? 2 Answers

animation and sound on collide 1 Answer

Play Sound on trigger 2 Answers

Sword Kills Enemies From Far Away 3 Answers

How to handle multiple colliders for one enemy and bullet. 3 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