Beam shoots off into space

I’m trying to create a basic flamethrower. One which has a flame particle follow your mouse, and a beam going between your mouse and the gun’s barrel.

I’m attempting to do this by setting the end attachment’s position to be the mouse’s position, however the gif below is the result, which is not what I want. The beam just shoots off into space. I’ve checked the point’s position, and it’s where it should be (using raycasting to the mouse).

https://gyazo.com/033c5bd47539eb80267a9579b8115954.mp4

Am I doing something wrong? Is this a bug?

Is the Attachment2 parented to something that’s at 0,0,0 with rotation 0,0,0 ?

2 Likes

Both attachments for the beam are inside the “Tip” part of the tool. I’m moving the “End” attachment around to the mouse and having the “Start” stay at the Tip.

1 Like

But if you set Mouse.hit.p as the Position of the Attachment won’t that be offset by the gun barrel not being at 0,0,0? Or did you already account for this?

I’m not following you.

1 Like

Attachments are offset from their parented part.

If you have a part at 0,10,0 and put an Attachment in it, the Attachment will always have an offset of 0,10,0 from the world-axis.

Your issue may be that you’re adding on Mouse.hit.p on top of the gun’s already offset CFrame (definitely not 0,0,0)

1 Like

Oh, so the position of an attachment is local rather than global?

If that’s true, then how would I accomplish what I’m after?

1 Like

Yes!

You can make a part at 0,0,0 and put the second attachment in there, or you can try putting it into terrain (although this is kind of hacky and might not be supported 5ever).

The other options is to use CFrame inverses to find the offset, but it’s much easier to just put the attachment into a part that’s at 0,0,0 lol

5 Likes

It looks like I can also put the end attachment inside a different part altogether, so I can put it inside the flame emitter where the mouse is!

Thanks, scripton!

2 Likes

np. Don’t forget to move this out of Client bugs :wink:

2 Likes

To stop supporting this, Terrain would have to stop inheriting from BasePart which would probably cause more problems than it’s worth. I’d say Terrain is a great location for all your Attachments-in-World-Space needs. I also use it for things like HandleAdornments.

The best part in my mind is that you can’t accidentally delete Terrain. It’s always there.