(REPOST) Is it possible to make an attachment auto-adjust itself down to where a part is?

(Repost because… last topic didn’t quite work out nor was there any further answers given)
I have no idea about how that would work but
Is there a way where I can make the beam’s second attachment detect if something is in the way, for example a player, or a part?

So… Is it possible to make an attachment auto-adjust itself down to where a part is, if so, how would i achieve something like that?
I want to have my Beam System be as realistic as possible, I don’t like beams colliding through* blocks or parts, or everything.

Script demonstration would be appreciated.

Location of the beam:
image

I would suggest using

for i,v in pairs (game.Workspace.TaLights:GetChildren()) do

in the script, because I have multiple instances of these inside of the Folder.

The following Attachment will be used in the script:
AttSky
image

Example: (sorry if the recording is laggy)

Thanks.

1 Like

You could run a service that uses a raycast to identify collisions. Set that collision point as the far end of the beam.

I don’t know anything about Raycast really :frowning_face_with_open_mouth:

It’s fairly simple actually. Especially with the new raycasting update they did last year.

1 Like

Intro to Raycasting (roblox.com)

They have a nice tutorial on it. Get familiar, try something out, and we can help from there. You know the 2 ends of the beam, that should be a good place to start.

(Raycasting is probably the single most useful thing I’ve learned on Roblox so far)

I’ll look into it, if I need any further assistance, I’ll continue on this topic.

1 Like

Found DevKing’s tutorial as well. Always a good place to learn. :slight_smile:

Advanced Roblox Scripting Tutorial #24 - Raycasting (Beginner to Pro 2019) - YouTube

hey man, I just made a light thing that you wanted to. Heres the file to it. :slight_smile:. If it works then feel free to use it in your game. And make this the solution(If this works of course!)
Light test for rando.rbxl (34.0 KB)

His tutorial is deprectated. The method he uses isn’t recommended by roblox.

1 Like

I can’t keep up with that yet. Thanks for the heads up. Now I have to watch it to see if this is what I learned.

I’m very confused with what’s happening ingame haha

XDDDDD. I’ll try to fix that but i think it’s because the part is unanchored. Btw this is my first time working with beams so I dont know much about them.

That’s alright, neither do I know.

Ah yes, DevKing.

I just watched a bit of it, I’m still confused :sweat_smile:

you need to set your raycast to whitelist, and have it only go over a map folder.
inside of that map folder is where you will put your map (basically anything you want to block the light beams your making)
then you (on the client) perform the raycasts for all of your beams, I’d say every other frame.
if you don’t know how to do stuff frame by frame, look into RunService.RenderStepped on the devhub.
if the raycast doesn’t hit, you set the attachment to it’s farthest possible position (the one shown in your original video) if the raycast does hit however, you put the attachments position to the hit position.
Again I’d reccomend checking the devhub for how raycasts work.

Yeah I noticed that the beam adjust itself to the middle of the baseplate.

RaycastResult.Position

Should return the point in space that the raycast hit. As opposed to

RaycastResult.Instance.Position

Which will return the center of the part hit.

So, I kinda fixed it except im not sure if it’s how u want it to be but I’ll still give u the place file here. oops wrong file…
Light test for rando.rbxl (34.3 KB)

Looks the same for me… I don’t know…
What I meant is, the beam end-attachment going to where the part position is
image

oops, I sent the wrong file. Look at the new file i put on the last file