I thought I’d just put this out there in case somebody has a quick answer (i.e a line or two of script) to my scenario.
I have a laser beam which has a point light attached to the end that hits things (hit.point)
This lights up the scenery around where the laser hits.
Problem:
The actual object that the laser hits (the ground, or a wall) doesn’t light up - because the light at the hit.point is exactly touching the object when it actually needs to stop a little short of the surface.
I figure I need to take the distance between the laser hit.point and the source of the laser and then move the light back towards the source a little, in order for the hit faces to be lit by the light.
Anyone with a snappy suggestion (even pointing me to the right page in the Unity manual) will save my brain some effort tonight when I eventually get the kids to bed and start up my Macbook after a long day in my boring day job.
Hmmmm… that might work but it would affect all collision detection in the level. Not sure I want my level scenery to have a collider that doesn’t quite fit. Still, I’m going to try that as it will only take a second
Scaling the collider doesn’t work, because it’s complex geometry with normals pointing in all directions (some inwards, some out), and also several different objects.
So I think I need to get the distance the laser beam extends and then subtract a little and move the light at the end of each update…
LaserStartPosition - HitPointPosition gives a Vector pointing from hitpoint to start. Normalize that vector to bring it to a length of 1 unit and add it to HitPointPosition. Set that as position of your light and it sits on the laser one unit before the hitpoint.
Where light is your light, collision is the Collision object you get from OnCollision(Enter/Exit/Stay), and movementFactor is some float that will determine how far back the light will move. If you’re raycasting replace “collision.contacts[0]” with your RaycastHit object.
Glad I could help, but I think you should give the solution burnumd posted a try also. It takes fewer code and depending on the shape of your target and from where it’s hit it could also look more realistic.