Laser Pointer needs a dot

Hi all.

I am making a showroom type scene and use a laserpointer to point out parts of an object.
It works fine, but i would like the laser to make a small red dot where it collides with a part.
Right now the part just breaks the laser beam.

How can i do that?

I use this script for the laser:

using UnityEngine;
using System.Collections;

public class Laser : MonoBehaviour
{

    private LineRenderer lr;
    // Use this for initialization
    void Start()
    {
        lr = GetComponent<LineRenderer>();
    }

    // Update is called once per frame
    void Update()
    {
        lr.SetPosition(0, transform.position);
        RaycastHit hit;
        if (Physics.Raycast(transform.position, transform.forward, out hit))
        {
            if (hit.collider)
            {
                lr.SetPosition(1, hit.point);
            }
        }
        else lr.SetPosition(1, transform.forward * 5000);
    }
}

some ideas:

  • small sphere gameobject with shiny emission material (that you move into that hit point, and far away if not hitting)
  • small quad mesh or sprite, maybe nice circle texture, align to hit.normal Unity - Scripting API: RaycastHit.normal
  • projector or even small spotlight near the hit.point, can move few centimeters backwards (to shine bright red light into that area)
2 Likes

Great ideas!

I am just not skilled enough to program it.
Could you help me out?

The AngryBots example/demo had a nice laser effect (for Aiming). It’s for an older version of Unity but you could give it a try.

How can you know that when you don’t try it? Try, fail, ask for help and learn from it. Just copying what others do for you helps you nothing (in regards to learning). So don’t be shy.

Edit: formatting

1 Like

Are you using SRP, HDRP, or URP?

I just use the standard one, URP i believe?

I will try and find a guide.

The suggestions from mgear sounded great, but i just dont know where to start.
So far i have been googling/youtubing tutorials for most of my code :slight_smile:

For future reference the standard one is actually called Built-In render pipeline. That’s what i meant when i mistakenly typed “SRP”.

I think you can use the projector component in that case.

1 Like

You can apply most solutions made for bullet holes like decals, should be even simpler because you don’t need a normal map like a hole/crack - not that a normal map is that much more work.

i might be repeating what the other guys said about the projectors, this might be what unity calls decals in the SRP i havn’t had too much experience with it yet

2 Likes

Thank you guys.
Now i at least know what to look for :smile:

I am very good at modelling in CAD and can muddle through 3DS Max, but am a total n00b at scripting.

Another easy laser-dot effect is to make a particle system with zero-speed particles, and give them some shimmering colors and varying sizes… that will give it a nice dynamic sizzling look if you do it right.

3 Likes

I might try doing a raycast from the pointer in the direction it is pointing, and at the collision point place a very small point light.

3 Likes

I am still trying to work out how to program this.
But thx for the ideas :smile: