- Home /
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:
-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;)
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.
Answer by GameTech · Jan 12, 2013 at 05:04 AM
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.
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.
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.
Your answer
Follow this Question
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