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

help making a code block add the lookvector property to a position?

Asked by 5 years ago
function movemodel()
    if model then
    mouse.TargetFilter = model
    end
    if isequipped == true and mouse.Target.Name == "NutrientPart" then
        local mousepos = mouse.Hit.p
    model:SetPrimaryPartCFrame(CFrame.new(mousepos))
    end
end

this function moves a model around as it is supposed to do but I ran into a slightly annoying problem.

another function rotates the model while this one just moves it around, but I noticed that when I move the model after I rotate it, the model does not keep its rotation that was set but rather re-aligns back to before it was rotated. I suspect this is because setting the position does not keep the rotation like CFrame does. how can I keep its current LookVector and still apply it to a position?

PS, I tried using just CFrame to move the model but doing this with the mouse makes it use the mouses LookVector which is undesirable.

1 answer

Log in to vote
0
Answered by
royaltoe 5144 Moderation Voter Community Moderator
5 years ago

Multiply by the current angle

angle = CFrame.Angles(0,90,0)
model:SetPrimaryPartCFrame(CFrame.new(mousepos) * angle)
Ad

Answer this question