How to make a part/attachment's rotation to follow a players mouse

Hello so I’m currently trying to make a blast wave superpower ability, and I’m trying to simply make a concept but it becomes very difficult to find how I can rotate an attachment to the mouse’s position, I try using body torque but I didn’t know it wouldn’t work on an attachment. The attachment would be located inside one of the player’s hand, there is a particle emitter inside the attachment which looks like a little blast wave effect. However, After reviewing all other forums I couldn’t find any solutions for my problem, I need the attachment to rotate to the player’s mouse position smoothly without any offset unless specified. Or at the very least a method to position the rotation of the attachment to another part, essentially the attachment facing another part. Thank you for anyone helping me to figure out this issue, I currently made a script just for the purpose of testing this out with the following code looking like:

RunService.HeartBeat:Connect(function()
    attachment.Orientation = Mouse.Hit.Position -- I also tried using LookVector * 100
end

https://i.gyazo.com/af0e9d464074c5f1dfa1922725fdb0af.gif

You don’t use orientation, you use CFrame.

CFrame is how you use position and orientation combined, but you can still only use one if you want.

RunService.HeartBeat:Connect(function()
    attachment.CFrame = CFrame.new(attachment.Position,Mouse.Hit.Position)
end

Try that, and tell us if it works.

1 Like

Hey, thank you so much this works really well on parts, but im not sure why when it comes to attachments things begin to get funky and barely even moves

Im not too experiencied with CFrame math but I see that it has worldposition values and just normal position, would this have anything to do with it?

Maybe, try WorldCFrame. If that doesn’t work, I believe I have something that works for orientation.

5 Likes
RunService.Heartbeat:Connect(function()
	RightHandAttachment.WorldCFrame = CFrame.new(RightHandAttachment.WorldPosition, Mouse.Hit.Position)
end)

Thank you!! The code above works, at first it didn’t but that was because the particle emission was set to top, I simply needed it to change it to another setting to make it work correctly. Thank you!!!

2 Likes