Search Unity

Flashlight does not work behind

Discussion in 'Getting Started' started by Nielsnetwork, May 19, 2015.

  1. Nielsnetwork

    Nielsnetwork

    Joined:
    May 17, 2015
    Posts:
    8
    i have created a flashlight connected to my fpscontroller and a terrian.
    The flashlight works fine except when i look behind me the flashlight goes black.
    Front
    Screenshot_Front.jpg Back: Screenshot_Back.jpg Thx 4 reading
     
  2. krougeau

    krougeau

    Joined:
    Jul 1, 2012
    Posts:
    456
    There seem to be several working examples for First Person Flashlight scripts in Unity, however if you'd like further assistance with your own, please provide a sample of your code (and please use the proper code tags to make it readable). Happy to assist once I can see what we're working with :)
     
  3. Nielsnetwork

    Nielsnetwork

    Joined:
    May 17, 2015
    Posts:
    8
    using System;
    using UnityEngine;
    using UnityStandardAssets.CrossPlatformInput;
    using UnityStandardAssets.Utility;
    using Random = UnityEngine.Random;

    namespace UnityStandardAssets.Characters.FirstPerson
    {
    [RequireComponent(typeof (CharacterController))]
    [RequireComponent(typeof (AudioSource))]
    public class FirstPersonController : MonoBehaviour
    {
    [SerializeField] private bool m_IsWalking;
    [SerializeField] private float m_WalkSpeed;
    [SerializeField] private float m_RunSpeed;
    [SerializeField] [Range(0f, 1f)] private float m_RunstepLenghten;
    [SerializeField] private float m_JumpSpeed;
    [SerializeField] private float m_StickToGroundForce;
    [SerializeField] private float m_GravityMultiplier;
    [SerializeField] private MouseLook m_MouseLook;
    [SerializeField] private bool m_UseFovKick;
    [SerializeField] private FOVKick m_FovKick = new FOVKick();
    [SerializeField] private bool m_UseHeadBob;
    [SerializeField] private CurveControlledBob m_HeadBob = new CurveControlledBob();
    [SerializeField] private LerpControlledBob m_JumpBob = new LerpControlledBob();
    [SerializeField] private float m_StepInterval;
    [SerializeField] private AudioClip[] m_FootstepSounds; // an array of footstep sounds that will be randomly selected from.
    [SerializeField] private AudioClip m_JumpSound; // the sound played when character leaves the ground.
    [SerializeField] private AudioClip m_LandSound; // the sound played when character touches back on ground.

    private Camera m_Camera;
    private bool m_Jump;
    private float m_YRotation;
    private Vector2 m_Input;
    private Vector3 m_MoveDir = Vector3.zero;
    private CharacterController m_CharacterController;
    private CollisionFlags m_CollisionFlags;
    private bool m_PreviouslyGrounded;
    private Vector3 m_OriginalCameraPosition;
    private float m_StepCycle;
    private float m_NextStep;
    private bool m_Jumping;
    private AudioSource m_AudioSource;

    // Use this for initialization
    private void Start()
    {
    m_CharacterController = GetComponent<CharacterController>();
    m_Camera = Camera.main;
    m_OriginalCameraPosition = m_Camera.transform.localPosition;
    m_FovKick.Setup(m_Camera);
    m_HeadBob.Setup(m_Camera, m_StepInterval);
    m_StepCycle = 0f;
    m_NextStep = m_StepCycle/2f;
    m_Jumping = false;
    m_AudioSource = GetComponent<AudioSource>();
    m_MouseLook.Init(transform , m_Camera.transform);
    }


    // Update is called once per frame
    private void Update()
    {
    RotateView();
    // the jump state needs to read here to make sure it is not missed
    if (!m_Jump)
    {
    m_Jump = CrossPlatformInputManager.GetButtonDown("Jump");
    }

    if (!m_PreviouslyGrounded && m_CharacterController.isGrounded)
    {
    StartCoroutine(m_JumpBob.DoBobCycle());
    PlayLandingSound();
    m_MoveDir.y = 0f;
    m_Jumping = false;
    }
    if (!m_CharacterController.isGrounded && !m_Jumping && m_PreviouslyGrounded)
    {
    m_MoveDir.y = 0f;
    }

    m_PreviouslyGrounded = m_CharacterController.isGrounded;
    }


    private void PlayLandingSound()
    {
    m_AudioSource.clip = m_LandSound;
    m_AudioSource.Play();
    m_NextStep = m_StepCycle + .5f;
    }


    private void FixedUpdate()
    {
    float speed;
    GetInput(out speed);
    // always move along the camera forward as it is the direction that it being aimed at
    Vector3 desiredMove = transform.forward*m_Input.y + transform.right*m_Input.x;

    // get a normal for the surface that is being touched to move along it
    RaycastHit hitInfo;
    Physics.SphereCast(transform.position, m_CharacterController.radius, Vector3.down, out hitInfo,
    m_CharacterController.height/2f);
    desiredMove = Vector3.ProjectOnPlane(desiredMove, hitInfo.normal).normalized;

    m_MoveDir.x = desiredMove.x*speed;
    m_MoveDir.z = desiredMove.z*speed;


    if (m_CharacterController.isGrounded)
    {
    m_MoveDir.y = -m_StickToGroundForce;

    if (m_Jump)
    {
    m_MoveDir.y = m_JumpSpeed;
    PlayJumpSound();
    m_Jump = false;
    m_Jumping = true;
    }
    }
    else
    {
    m_MoveDir += Physics.gravity*m_GravityMultiplier*Time.fixedDeltaTime;
    }
    m_CollisionFlags = m_CharacterController.Move(m_MoveDir*Time.fixedDeltaTime);

    ProgressStepCycle(speed);
    UpdateCameraPosition(speed);
    }


    private void PlayJumpSound()
    {
    m_AudioSource.clip = m_JumpSound;
    m_AudioSource.Play();
    }


    private void ProgressStepCycle(float speed)
    {
    if (m_CharacterController.velocity.sqrMagnitude > 0 && (m_Input.x != 0 || m_Input.y != 0))
    {
    m_StepCycle += (m_CharacterController.velocity.magnitude + (speed*(m_IsWalking ? 1f : m_RunstepLenghten)))*
    Time.fixedDeltaTime;
    }

    if (!(m_StepCycle > m_NextStep))
    {
    return;
    }

    m_NextStep = m_StepCycle + m_StepInterval;

    PlayFootStepAudio();
    }


    private void PlayFootStepAudio()
    {
    if (!m_CharacterController.isGrounded)
    {
    return;
    }
    // pick & play a random footstep sound from the array,
    // excluding sound at index 0
    int n = Random.Range(1, m_FootstepSounds.Length);
    m_AudioSource.clip = m_FootstepSounds[n];
    m_AudioSource.PlayOneShot(m_AudioSource.clip);
    // move picked sound to index 0 so it's not picked next time
    m_FootstepSounds[n] = m_FootstepSounds[0];
    m_FootstepSounds[0] = m_AudioSource.clip;
    }


    private void UpdateCameraPosition(float speed)
    {
    Vector3 newCameraPosition;
    if (!m_UseHeadBob)
    {
    return;
    }
    if (m_CharacterController.velocity.magnitude > 0 && m_CharacterController.isGrounded)
    {
    m_Camera.transform.localPosition =
    m_HeadBob.DoHeadBob(m_CharacterController.velocity.magnitude +
    (speed*(m_IsWalking ? 1f : m_RunstepLenghten)));
    newCameraPosition = m_Camera.transform.localPosition;
    newCameraPosition.y = m_Camera.transform.localPosition.y - m_JumpBob.Offset();
    }
    else
    {
    newCameraPosition = m_Camera.transform.localPosition;
    newCameraPosition.y = m_OriginalCameraPosition.y - m_JumpBob.Offset();
    }
    m_Camera.transform.localPosition = newCameraPosition;
    }


    private void GetInput(out float speed)
    {
    // Read input
    float horizontal = CrossPlatformInputManager.GetAxis("Horizontal");
    float vertical = CrossPlatformInputManager.GetAxis("Vertical");

    bool waswalking = m_IsWalking;

    #if !MOBILE_INPUT
    // On standalone builds, walk/run speed is modified by a key press.
    // keep track of whether or not the character is walking or running
    m_IsWalking = !Input.GetKey(KeyCode.LeftShift);
    #endif
    // set the desired speed to be walking or running
    speed = m_IsWalking ? m_WalkSpeed : m_RunSpeed;
    m_Input = new Vector2(horizontal, vertical);

    // normalize input if it exceeds 1 in combined length:
    if (m_Input.sqrMagnitude > 1)
    {
    m_Input.Normalize();
    }

    // handle speed change to give an fov kick
    // only if the player is going to a run, is running and the fovkick is to be used
    if (m_IsWalking != waswalking && m_UseFovKick && m_CharacterController.velocity.sqrMagnitude > 0)
    {
    StopAllCoroutines();
    StartCoroutine(!m_IsWalking ? m_FovKick.FOVKickUp() : m_FovKick.FOVKickDown());
    }
    }


    private void RotateView()
    {
    m_MouseLook.LookRotation (transform, m_Camera.transform);
    }


    private void OnControllerColliderHit(ControllerColliderHit hit)
    {
    Rigidbody body = hit.collider.attachedRigidbody;
    //dont move the rigidbody if the character is on top of it
    if (m_CollisionFlags == CollisionFlags.Below)
    {
    return;
    }

    if (body == null || body.isKinematic)
    {
    return;
    }
    body.AddForceAtPosition(m_CharacterController.velocity*0.1f, hit.point, ForceMode.Impulse);
    }
    }
    }
     
  4. krougeau

    krougeau

    Joined:
    Jul 1, 2012
    Posts:
    456
    Please click the using proper code tags link provided, read over it, and edit your post so it's not such a mess to read. Thanks!
     
    larku likes this.
  5. Nielsnetwork

    Nielsnetwork

    Joined:
    May 17, 2015
    Posts:
    8
    Code (CSharp):
    1. using System;
    2. using UnityEngine;
    3. using UnityStandardAssets.CrossPlatformInput;
    4. using UnityStandardAssets.Utility;
    5. using Random = UnityEngine.Random;
    6.  
    7. namespace UnityStandardAssets.Characters.FirstPerson
    8. {
    9.     [RequireComponent(typeof (CharacterController))]
    10.     [RequireComponent(typeof (AudioSource))]
    11.     public class FirstPersonController : MonoBehaviour
    12.     {
    13.         [SerializeField] private bool m_IsWalking;
    14.         [SerializeField] private float m_WalkSpeed;
    15.         [SerializeField] private float m_RunSpeed;
    16.         [SerializeField] [Range(0f, 1f)] private float m_RunstepLenghten;
    17.         [SerializeField] private float m_JumpSpeed;
    18.         [SerializeField] private float m_StickToGroundForce;
    19.         [SerializeField] private float m_GravityMultiplier;
    20.         [SerializeField] private MouseLook m_MouseLook;
    21.         [SerializeField] private bool m_UseFovKick;
    22.         [SerializeField] private FOVKick m_FovKick = new FOVKick();
    23.         [SerializeField] private bool m_UseHeadBob;
    24.         [SerializeField] private CurveControlledBob m_HeadBob = new CurveControlledBob();
    25.         [SerializeField] private LerpControlledBob m_JumpBob = new LerpControlledBob();
    26.         [SerializeField] private float m_StepInterval;
    27.         [SerializeField] private AudioClip[] m_FootstepSounds;    // an array of footstep sounds that will be randomly selected from.
    28.         [SerializeField] private AudioClip m_JumpSound;           // the sound played when character leaves the ground.
    29.         [SerializeField] private AudioClip m_LandSound;           // the sound played when character touches back on ground.
    30.  
    31.         private Camera m_Camera;
    32.         private bool m_Jump;
    33.         private float m_YRotation;
    34.         private Vector2 m_Input;
    35.         private Vector3 m_MoveDir = Vector3.zero;
    36.         private CharacterController m_CharacterController;
    37.         private CollisionFlags m_CollisionFlags;
    38.         private bool m_PreviouslyGrounded;
    39.         private Vector3 m_OriginalCameraPosition;
    40.         private float m_StepCycle;
    41.         private float m_NextStep;
    42.         private bool m_Jumping;
    43.         private AudioSource m_AudioSource;
    44.  
    45.         // Use this for initialization
    46.         private void Start()
    47.         {
    48.             m_CharacterController = GetComponent<CharacterController>();
    49.             m_Camera = Camera.main;
    50.             m_OriginalCameraPosition = m_Camera.transform.localPosition;
    51.             m_FovKick.Setup(m_Camera);
    52.             m_HeadBob.Setup(m_Camera, m_StepInterval);
    53.             m_StepCycle = 0f;
    54.             m_NextStep = m_StepCycle/2f;
    55.             m_Jumping = false;
    56.             m_AudioSource = GetComponent<AudioSource>();
    57.             m_MouseLook.Init(transform , m_Camera.transform);
    58.         }
    59.  
    60.  
    61.         // Update is called once per frame
    62.         private void Update()
    63.         {
    64.             RotateView();
    65.             // the jump state needs to read here to make sure it is not missed
    66.             if (!m_Jump)
    67.             {
    68.                 m_Jump = CrossPlatformInputManager.GetButtonDown("Jump");
    69.             }
    70.  
    71.             if (!m_PreviouslyGrounded && m_CharacterController.isGrounded)
    72.             {
    73.                 StartCoroutine(m_JumpBob.DoBobCycle());
    74.                 PlayLandingSound();
    75.                 m_MoveDir.y = 0f;
    76.                 m_Jumping = false;
    77.             }
    78.             if (!m_CharacterController.isGrounded && !m_Jumping && m_PreviouslyGrounded)
    79.             {
    80.                 m_MoveDir.y = 0f;
    81.             }
    82.  
    83.             m_PreviouslyGrounded = m_CharacterController.isGrounded;
    84.         }
    85.  
    86.  
    87.         private void PlayLandingSound()
    88.         {
    89.             m_AudioSource.clip = m_LandSound;
    90.             m_AudioSource.Play();
    91.             m_NextStep = m_StepCycle + .5f;
    92.         }
    93.  
    94.  
    95.         private void FixedUpdate()
    96.         {
    97.             float speed;
    98.             GetInput(out speed);
    99.             // always move along the camera forward as it is the direction that it being aimed at
    100.             Vector3 desiredMove = transform.forward*m_Input.y + transform.right*m_Input.x;
    101.  
    102.             // get a normal for the surface that is being touched to move along it
    103.             RaycastHit hitInfo;
    104.             Physics.SphereCast(transform.position, m_CharacterController.radius, Vector3.down, out hitInfo,
    105.                                m_CharacterController.height/2f);
    106.             desiredMove = Vector3.ProjectOnPlane(desiredMove, hitInfo.normal).normalized;
    107.  
    108.             m_MoveDir.x = desiredMove.x*speed;
    109.             m_MoveDir.z = desiredMove.z*speed;
    110.  
    111.  
    112.             if (m_CharacterController.isGrounded)
    113.             {
    114.                 m_MoveDir.y = -m_StickToGroundForce;
    115.  
    116.                 if (m_Jump)
    117.                 {
    118.                     m_MoveDir.y = m_JumpSpeed;
    119.                     PlayJumpSound();
    120.                     m_Jump = false;
    121.                     m_Jumping = true;
    122.                 }
    123.             }
    124.             else
    125.             {
    126.                 m_MoveDir += Physics.gravity*m_GravityMultiplier*Time.fixedDeltaTime;
    127.             }
    128.             m_CollisionFlags = m_CharacterController.Move(m_MoveDir*Time.fixedDeltaTime);
    129.  
    130.             ProgressStepCycle(speed);
    131.             UpdateCameraPosition(speed);
    132.         }
    133.  
    134.  
    135.         private void PlayJumpSound()
    136.         {
    137.             m_AudioSource.clip = m_JumpSound;
    138.             m_AudioSource.Play();
    139.         }
    140.  
    141.  
    142.         private void ProgressStepCycle(float speed)
    143.         {
    144.             if (m_CharacterController.velocity.sqrMagnitude > 0 && (m_Input.x != 0 || m_Input.y != 0))
    145.             {
    146.                 m_StepCycle += (m_CharacterController.velocity.magnitude + (speed*(m_IsWalking ? 1f : m_RunstepLenghten)))*
    147.                              Time.fixedDeltaTime;
    148.             }
    149.  
    150.             if (!(m_StepCycle > m_NextStep))
    151.             {
    152.                 return;
    153.             }
    154.  
    155.             m_NextStep = m_StepCycle + m_StepInterval;
    156.  
    157.             PlayFootStepAudio();
    158.         }
    159.  
    160.  
    161.         private void PlayFootStepAudio()
    162.         {
    163.             if (!m_CharacterController.isGrounded)
    164.             {
    165.                 return;
    166.             }
    167.             // pick & play a random footstep sound from the array,
    168.             // excluding sound at index 0
    169.             int n = Random.Range(1, m_FootstepSounds.Length);
    170.             m_AudioSource.clip = m_FootstepSounds[n];
    171.             m_AudioSource.PlayOneShot(m_AudioSource.clip);
    172.             // move picked sound to index 0 so it's not picked next time
    173.             m_FootstepSounds[n] = m_FootstepSounds[0];
    174.             m_FootstepSounds[0] = m_AudioSource.clip;
    175.         }
    176.  
    177.  
    178.         private void UpdateCameraPosition(float speed)
    179.         {
    180.             Vector3 newCameraPosition;
    181.             if (!m_UseHeadBob)
    182.             {
    183.                 return;
    184.             }
    185.             if (m_CharacterController.velocity.magnitude > 0 && m_CharacterController.isGrounded)
    186.             {
    187.                 m_Camera.transform.localPosition =
    188.                     m_HeadBob.DoHeadBob(m_CharacterController.velocity.magnitude +
    189.                                       (speed*(m_IsWalking ? 1f : m_RunstepLenghten)));
    190.                 newCameraPosition = m_Camera.transform.localPosition;
    191.                 newCameraPosition.y = m_Camera.transform.localPosition.y - m_JumpBob.Offset();
    192.             }
    193.             else
    194.             {
    195.                 newCameraPosition = m_Camera.transform.localPosition;
    196.                 newCameraPosition.y = m_OriginalCameraPosition.y - m_JumpBob.Offset();
    197.             }
    198.             m_Camera.transform.localPosition = newCameraPosition;
    199.         }
    200.  
    201.  
    202.         private void GetInput(out float speed)
    203.         {
    204.             // Read input
    205.             float horizontal = CrossPlatformInputManager.GetAxis("Horizontal");
    206.             float vertical = CrossPlatformInputManager.GetAxis("Vertical");
    207.  
    208.             bool waswalking = m_IsWalking;
    209.  
    210. #if !MOBILE_INPUT
    211.             // On standalone builds, walk/run speed is modified by a key press.
    212.             // keep track of whether or not the character is walking or running
    213.             m_IsWalking = !Input.GetKey(KeyCode.LeftShift);
    214. #endif
    215.             // set the desired speed to be walking or running
    216.             speed = m_IsWalking ? m_WalkSpeed : m_RunSpeed;
    217.             m_Input = new Vector2(horizontal, vertical);
    218.  
    219.             // normalize input if it exceeds 1 in combined length:
    220.             if (m_Input.sqrMagnitude > 1)
    221.             {
    222.                 m_Input.Normalize();
    223.             }
    224.  
    225.             // handle speed change to give an fov kick
    226.             // only if the player is going to a run, is running and the fovkick is to be used
    227.             if (m_IsWalking != waswalking && m_UseFovKick && m_CharacterController.velocity.sqrMagnitude > 0)
    228.             {
    229.                 StopAllCoroutines();
    230.                 StartCoroutine(!m_IsWalking ? m_FovKick.FOVKickUp() : m_FovKick.FOVKickDown());
    231.             }
    232.         }
    233.  
    234.  
    235.         private void RotateView()
    236.         {
    237.             m_MouseLook.LookRotation (transform, m_Camera.transform);
    238.         }
    239.  
    240.  
    241.         private void OnControllerColliderHit(ControllerColliderHit hit)
    242.         {
    243.             Rigidbody body = hit.collider.attachedRigidbody;
    244.             //dont move the rigidbody if the character is on top of it
    245.             if (m_CollisionFlags == CollisionFlags.Below)
    246.             {
    247.                 return;
    248.             }
    249.  
    250.             if (body == null || body.isKinematic)
    251.             {
    252.                 return;
    253.             }
    254.             body.AddForceAtPosition(m_CharacterController.velocity*0.1f, hit.point, ForceMode.Impulse);
    255.         }
    256.     }
    257. }
    258.  
    This better? sorry i am a newbie to all of this... i hope it works
     
    krougeau likes this.
  6. krougeau

    krougeau

    Joined:
    Jul 1, 2012
    Posts:
    456
    Much better :) While I look over the code, you could delete the above, non-formatted post & it will be easier for other users to look through this thread. I'll remove my own superfluous comments then as well. Thanks!
     
  7. krougeau

    krougeau

    Joined:
    Jul 1, 2012
    Posts:
    456
    My apologies. The code you've supplied is for the FirstPersonController. I would like to see the code from your Flashlight object please.
     
  8. Nielsnetwork

    Nielsnetwork

    Joined:
    May 17, 2015
    Posts:
    8
    i just put a spotlight on the FPScontroller and called it flashlight, i did not make a script.
    I think there is something wrong with my terrain i checked it and my flashlight only does not work on the ground, the flashlight works fine on a wall 4 example. Example.jpg
     
  9. krougeau

    krougeau

    Joined:
    Jul 1, 2012
    Posts:
    456
    Oh, I see. I noticed in your first set of screenshots that you had a Flashlight.js script, so I assumed that was what you were using. Let me look over the screenshots and see if I can spot anything out of the ordinary.
     
  10. krougeau

    krougeau

    Joined:
    Jul 1, 2012
    Posts:
    456
    Well, I don't see anything amiss. I even tried setting up a quick sample scene for testing and, using the same values you are, I had no trouble illuminating regular terrain or other game objects in the scene. That being the case, I went back over the sample scene and changed my terrain and walls to be completely black, which did drastically reduce the amount of illumination from the flashlight. What sort of textures are you using for your terrain, etc? Oh, and are you using a standard Unity terrain, or are you using a cube or plane?
     
  11. Nielsnetwork

    Nielsnetwork

    Joined:
    May 17, 2015
    Posts:
    8
    upload_2015-5-25_15-24-36.png
    I used a standard terrain of unity, ConcreteNew0012_1_thumblarge is my ground
    (Renamed terrain to Main_Ground)
    Lightning tab:
    upload_2015-5-25_15-27-33.png
    Thx 4 helping me, when the game is done ill put youre name in the credits :)
     

    Attached Files:

  12. krougeau

    krougeau

    Joined:
    Jul 1, 2012
    Posts:
    456
    Hmmm... Well, I'm using as close to your settings as I can, including your terrain image, and it's working fine for me. Would you please take a screenshot of your terrain settings (the gear icon at the far right of the Terrain menu) so that I can see if we have any differences there? One thing that might also be causing trouble is I see that you're using DirectX 11 settings on a DirectX 10 GPU. I can't say for sure, but it could be responsible...
     
  13. krougeau

    krougeau

    Joined:
    Jul 1, 2012
    Posts:
    456
    Also, just to make sure it's not something really simple... Your flashlight moves and follows your player's line of sight, correct? It looks like you have it parented to the FirstPersonCharacter object, so it should, but I thought I'd double check.
     
  14. Nielsnetwork

    Nielsnetwork

    Joined:
    May 17, 2015
    Posts:
    8
    upload_2015-5-25_16-40-47.png
    Here you go. Is there a way to update directX? or should i downgrade to unity 4 or something?
     
  15. krougeau

    krougeau

    Joined:
    Jul 1, 2012
    Posts:
    456
    Looks like our settings match there, too. Alright, in case it's a DirectX issue, you can go into Build Settings, then Settings for PC, Mac & Linux Standalone, then scroll down & click Other Settings at the bottom and you'll find a checkbox that says Use Direct3D 11. Uncheck that and hit Apply when it asks you to. It may take a minute, but after that you'll see <DX9> at the end of the Unity Title bar. Run it that way and see if it makes any difference at all. It didn't on my end, but it was already working for me, so it's hard to tell :)
     
  16. krougeau

    krougeau

    Joined:
    Jul 1, 2012
    Posts:
    456
    Oh no! I took another look at your first screenshots and see now that I was mistaken... This should be a really easy fix, lol, ignore the changes suggested above...

    You have your spotlight/flashlight parented to the FPSController, but you NEED to have it parented to the FirstPersonCharacter so it will move with your character and follow their line of sight.

    Do that and it should work fine. I thought it looked right earlier, but looking again I see that I was mistaken. I'm pretty tired, so I'm not surprised I missed it. *sigh* Sorry, we could have had you fixed up an hour ago.
     
  17. Nielsnetwork

    Nielsnetwork

    Joined:
    May 17, 2015
    Posts:
    8
    ... it still does not work... sorry
     
  18. krougeau

    krougeau

    Joined:
    Jul 1, 2012
    Posts:
    456
    It's quite alright. I just wish there were more I could do to assist you...

    Just to make sure, your flashlight is now properly parented to the FirstPersonCharacter object which is itself a child of the FPSController object, correct? When you face forward, you see the flashlight beam? If you move the character's head up and down, left or right, does the flashlight track with it properly?

    If all of that works, but you still can't get it to shine behind you, then I'm not sure what the problem might be. I've tested it several different ways now myself and am having very little in the way of trouble other than when the textures the light is shining on are way too dark. Even if they're completely black, I can make out at least a bit of the light... Weird.
     
    NomadKing likes this.
  19. Nielsnetwork

    Nielsnetwork

    Joined:
    May 17, 2015
    Posts:
    8
    thanks 4 youre help. ill put you in the Thanks section in the credits when my game is done
     
  20. krougeau

    krougeau

    Joined:
    Jul 1, 2012
    Posts:
    456
    I'm uploading a sample project to my Dropbox for you and will be back with a link once it's ready. When it is, start a brand new project and import the package, then open the "test" scene and see if my sample version works any better for you. This way we'll know for sure if it's your computer, your copy of Unity, your setup, or something else entirely that's at fault. Oh, and you'll most likely need the latest version of Unity (5.0.2) since that's what I'm using.
     
    NomadKing likes this.
  21. krougeau

    krougeau

    Joined:
    Jul 1, 2012
    Posts:
    456
    OK, here's a link to the sample project. It's a little over 100mb and should contain all that you need for testing, so open it in a new project and import the package there so you don't mess up anything you're currently working on.
    https://www.dropbox.com/s/gszx60yjp9453l5/FlashlightTest.unitypackage?dl=0

    Oh, and let me know when you've got it so I can remove it & save some space. Thanks! Hope it works for ya.
     
    NomadKing likes this.
  22. giano574

    giano574

    Joined:
    Nov 28, 2013
    Posts:
    76
    Shouldn't the spotlight be parented to the camera?
     
  23. krougeau

    krougeau

    Joined:
    Jul 1, 2012
    Posts:
    456
    Yes, and in this instance, the camera is called "FirstPersonCharacter". I asked a couple of times to make sure that was the case...
     
  24. RazorCat272

    RazorCat272

    Joined:
    Jun 15, 2015
    Posts:
    1
    I know this thread is a couple weeks old but I think I found the solution (at least for my issue).
    I was experiencing the same problem and it was because I had the texture for the terrain set in the Albedo and Normal box in the Terrain Texture pop-up. I deleted the texture from "Normal" and the spot light worked fine!
     
    krougeau likes this.