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

Set CFrame position without rotating?

Asked by 7 years ago
Edited 7 years ago

When I click the mouse, the game spawns in a model to my mouse position but I dont know how to set the model's position to the mouse position without rotating the model. It's taken me ages to try figure it out but i cant get my head around Cframe.

local player = game.Players.LocalPlayer local mouse = player:GetMouse()

function place() local foundation = game.ReplicatedStorage.Foundation:Clone() foundation.Parent = game.Workspace local x, y, z = mouse.Hit:toEulerAnglesXYZ()
foundation:SetPrimaryPartCFrame(mouse.Hit.Position * CFrame.fromEulerAnglesXYZ(-x,-y,-z)) end

mouse.Button1Up:connect(place)

0
Can you put it in a code block please? Ultimate_Piccolo 201 — 7y

1 answer

Log in to vote
0
Answered by
Vulkarin 581 Moderation Voter
7 years ago

I tried this myself and it seemed to work fine...but I am sure there are probably much easier ways to do it

local mouse = game.Players.LocalPlayer:GetMouse()

function place()
    local foundation = game.Workspace.Model
    local primPart = foundation.Part
    foundation.PrimaryPart = primPart
    foundation:SetPrimaryPartCFrame(primPart.CFrame + (mouse.Hit.p - primPart.CFrame.p))
end

mouse.Button1Up:connect(place)
Ad

Answer this question