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

How to make a part facing the direction from the character to the mouse?

Asked by 6 years ago

I want to make a skateboard spawning script that when ever you click the skateboard spawns where your mouse is, but I also want it to face the direction from my torso to the mouse. But how??

I believed that this involves in .unit and something with CFrame.new(position, position)

1 answer

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

I believe something like this might work:

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
mouse.Button1Up:Connect(function()
    local board = --set to skateboard part
    local direction = (mouse.Hit.p-plr.Character.HumanoidRootPart.Position).unit
    direction = direction * Vector3.new(1,0,1) --keep line if you only want rotation on y axis
    board.CFrame = CFrame.new(mouse.Hit.p,mouse.Hit.p + direction)
end)    

Keep in mind if the game is FilteringEnabled you will have to use RemoteEvents to create the skateboard.

Ad

Answer this question