Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make parts point in the direction of the mouse?

I'm making a turret for my tank game, how would I make all the parts in the turret face the mouse? Also, how would I make it so if the mouse is closer to the top of the screen, it only moves the barrel?

1 answer

✓ Accepted answer

Lets start about thinking about CFrame, CFrame can be made in 2 ways, first is the basic

CFrame.new(0,0,0)

However there is also another way! If say a part's orriginal CFrame was 0,10,5 and you wanted to have this part's lookvector point a position you can do like so

Part.CFrame = CFrame.new(Vector3.new(0,10,5),Vector3.new(0,0,0))

This would make the part's CFrame 0,10,5 and the part would face 0,0,0

So now if we think that we can use the mouse position, then after you find the mouse you can use mouse.p as the second vector3

So we end up with something like this:

Part.CFrame = CFrame.new(Part.CFrame.p,mouse.p)

You'll now need to experiment with this mixed with welds in order to pull off what you are looking for, if you need further help PM me on roblox and I can explain more!

1 comment

0

Very helpful, thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.