You can use RayCasting for this! Ray casting allows you to shoot a ray from the barrel to where the player clicks. Then you can get the part that the ray hit as well as the position the ray hit.
I see! The article I linked shows how you can do that! You need to position the beam half way in between the origin and hit point of the ray (you can average two positions to get the center like this (pos1 + pos2)/2!), scale its Z (forward/backward) size to the distance (magnitude) between the two points, and point it towards the hit point (or origin) of the ray.
i was going to do it by placing the attachment it is linked to at the place i am shooting at. if you saw in the model i sent, it is a beam not a part. the part is just a holder for the attachments
You would want to set the Attachment0 position to the origin position of the ray, the Attachment1 position to the position that was hit, and the CurveSizes to the height for each half of the curve, or 0 if you don’t want any curving.
That’s close but you’d probably want to use WorldPosition instead of Position since Position will offset relative to the beam part’s position. If the beam part’s position is 0,0,0 this will work as intended though. Make sure Target and hitFromPos are both Vector3 values too!
Yep! You’d need the beam part that has the beam to be in the workspace. You can also make the beam part the tool’s handle if you wanted to (although I don’t know how WorldPosition behaves this way so I don’t know if moving the character will cause problems).
Are you trying to make the beam connect to the handle of the tool and follow it? If you are, you could place the Attachment1 of the beam in the hit part. That will cause Attachment1 to move relative to the hit part. And the Attachment0 could be in the tool’s handle so it moves relative to the handle.