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

How can I make a tool in first person point towards the mouse position?

Asked by
RoboFrog 400 Moderation Voter
9 years ago

I asked a similar question about 4-5 days back, but there was widespread confusion on many elements of the question.

I'm nearly done with making a fully custom combat system, but am stuck on one last error -- making a spear, for instance, rotate its model in order to point at the mouse location.

I've already made the inner-workings of the tool a model (other than handle, which is invisible anyways) which sets its primary part to the part which would need rotation. After this, I can assume that raycasting would be my best bet, though I've not yet had a remotely working prototype.

If this would be more easily possible by rotating the arm instead of the tool, I can assume it'd be around the same code as stated in the paragraph above (since the raycasting is my only issue).

I'm not requesting a full code be made, just general tips and ideas on how I could make this system a reality (since I have no idea what I'm doing with raycasting).

Thanks for reading, and I hope to find a solution!

EDIT: I've tried this code from MastaJames to no avail --

local model = game.Workspace.Model
local mouse = game.Players.LocalPlayer:GetMouse()

mouse.Move:connect(function()
    if mouse.Hit then
        model:SetPrimaryPartCFrame(CFrame.new(model:GetPrimaryPartCFrame().p, mouse.Hit.p))
    end
end)

Also, as a slight mini question, the weapon now becomes invisible with the player when in first person mode. Is this because the inner parts are a model rather than just separate parts?

0
I would first try playing with the CFrame.new(Vector3 startPosition, Vector3 lookAt) constructor. Perci1 4988 — 9y
0
That's the first place I went to as well. It was then suggested to me again in my previous thread, however the code never worked out (even with mouse.Hit.p as the lookAt). RoboFrog 400 — 9y
0
The reason it's invisible when you zoom in is because it is located inside of the player model. Aethex 256 — 9y
0
Strange, it didn't do that about a week ago, nor did any of my other tools. Must have been an update recently then. RoboFrog 400 — 9y

Answer this question