Laser beam alligning between two points [RESOLVED]

Hello! I am trying to figure out how to align the ends so that they are always pointing towards the two parts if that makes any sense, at the tip of the gun is a part and at the end of where the mouse hits is another part that is generated. Currently my plan is to position bones so I can give it a wavy effect, but I have ran into some issues when moving the actual rigged cylinder there before moving the bones, it isn’t positioning properly.

My goal looks something like this, but I can’t seem to find searches that are pertaining to this situation unless I’m not using the right keywords

image

Since as seen in the photo of the game, it is more like this
image

The laser would also work just anyway, if you were to point it on the ground it would still be straight between those two points if that makes any sense. I apologize if this is confusing but I’d appreciate any advice that will point me in the right direction. Thank you in advance!

You could try to use CFrame.lookAt() to set the position and get the part to look at Part B.

Laser.CFrame = CFrame.lookAt(Position, PartB.CFrame, Vector3.yAxis)

-- Vector3.yAxis is the UP axis it's using for alignment, just mess with it till it works
1 Like

It definitely does do something which I noticed, but it doesn’t necessarily go inbetween the points if that makes any sense. It would be something like this:

image

But it still does this:

image

Here is a glimpse of the code I used using what you suggested to me, would it just be the matter of changing the Vector3 or something like that?

streamEffect.CFrame = CFrame.lookAt(CenterPosition, hitPart.Position, Vector3.yAxis)

I apologize if this is asking too much, but I appreciate the help.

The perspective on the images is confusing me on what the “intended” goal is however I’m guessing? that the “streamEffect” part is rotated the wrong way.

You can change the axis it is aligning by changing: Vector3.yAxis, to Vector3.xAxis or Vector3.zAxis.

If that STILL doesn’t work, I imagine you could just manually apply a rotation.
Something like:

streamEffect.CFrame = CFrame.lookAt(CenterPosition, hitPart.Position, Vector3.yAxis) * CFrame.Angles(0, math.rad(90),0)

That helped! Thank you so much!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.