- Home /
Question by
shockkgms · Jan 01, 2020 at 05:17 PM ·
raycastraycastingflashlightpointlight
Flashlight with fake bounce point light
public float MaxRange;
public GameObject Flashlight;
public GameObject BounceLight;
public GameObject HitPoint;
public Vector3 BounceLightPos;
public Vector3 nolightpos;
void Update()
{
RaycastHit hit;
Ray ray = new Ray(Flashlight.transform.position, Flashlight.transform.forward);
if (Physics.Raycast(ray, out hit, MaxRange))
{
BounceLightPos = hit.point;
BounceLight.transform.position = BounceLightPos;
}
else
{
BounceLightPos = nolightpos;
BounceLight.transform.position = BounceLightPos;
}
HitPoint.transform.position = BounceLightPos;
}
I want to make a flashlight system like how half life 1 has. But just for flashlight causing fake bounce pointlight from the wall.
So, everything is working as it should, but the point light sticks in the wall causing it to not light the wall, just range of the point light. So how can i make the pointlight light the wall and the range too?
Comment
Answer by Jasan_Alan · Jun 25, 2021 at 03:35 PM
Try moving the light back using the flashlight's transform.forward, so after moving the point light to the wall:
BounceLight.transform.position += flashlight.transform.forward.normalized;
Not sure if this will work or not, but it's worth a try. The ".normalized" at the end is so it will (hopefully) produce consistent results.