Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Mowblow 117
11 years ago

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

Log in to vote
2
Answered by
Vathriel 510 Moderation Voter
11 years ago

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

1CFrame.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

1Part.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:

1Part.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!

0
Very helpful, thanks! Mowblow 117 — 11y
Ad

Answer this question