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

How would I force player to smoothly turn at part?

Asked by 3 years ago
function lookAt2(chr,target)
    if chr.PrimaryPart then
        local chrPos=chr.PrimaryPart.Position
        local tPos=target.Position
        local newCF=CFrame.new(chrPos,tPos)
        chr:SetPrimaryPartCFrame(newCF)
    end
end

lookAt2(char,v.HumanoidRootPart)

basically I'm using this function in order to make player rotate to certain target but its all choppy and not smooth so I was wondering how I could make it, I was looking everywhere and only solution was using tween service and CFrame.Angles(0,math.rad(n),0) but I need it to rotate to a certain part and I don't know how to do that with tween service and .Angles, anyone knows how I can make it work?

2 answers

Log in to vote
2
Answered by
ACHRONlX 255 Moderation Voter
3 years ago

You should use TweenService.

local function LookAt(A, B)
    if not A.PrimaryPart then return end
    game:GetService('TweenService'):Create(A.PrimaryPart, TweenInfo.new(1), {CFrame = CFrame.new(A.PrimaryPart.Posirion, b.Position)}):Play();
end

LookAt(char, v.HumanoidRootPart);

Let me know if this helps.

Ad
Log in to vote
1
Answered by
iOwn_You 543 Moderation Voter
3 years ago
Edited 3 years ago

You should use TweenService to smoothly change values.

TweenService API

EDIT: Just read your question more throughly, you should use a BodyGyro inside of HumanoidRootPart to smoothly rotate the character at the desired force;

BodyGyro API

0
it doesn't quiet helps me because I don't know how to use it that way, I can't change it smoothly using tweenservice because it uses setprimarypartcframe SuAkihiro 94 — 3y
0
Edited my answer. iOwn_You 543 — 3y

Answer this question