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

How do I make my pet look in the direction I'm facing?

Asked by 2 years ago

basically this is the only script I can find that works but it doesn't rotate the pet to the direction I'm facing.

Here is my code:

local char = script.Parent.Parent
local hum = char:FindFirstChild("Humanoid")
local Head = char:FindFirstChild("Head")
local pet = script.Parent


local maxFloat = 1
local floatInc = 0.025
local sw = false
local fl = 0

while true do
    wait()
    if not sw then
        fl = fl + floatInc
        if fl >= maxFloat then
            sw = true
        end
    else
        fl = fl - floatInc
        if fl <=-maxFloat then
            sw = false
        end
    end
    if pet ~= nil and hum ~= nil and Head ~= nil then
        if hum.Health >= 0 then
            local cf = Head.CFrame * CFrame.new(3,2+fl,3)
            pet.BodyPosition.Position = Vector3.new(cf.x,cf.y,cf.z)
            pet.BodyGyro.CFrame = Head.CFrame * CFrame.new(3,0,-3)
        else
            break
        end
    end
end

The whole pet with the script inside is under StarterCharacterScripts.

If anyone can help me or even find a better script with working rotation it would be greatly appreciated.

Thanks!

0
hey dude, sorry but I just saw your comment now. I see you’ve accepted my answer so do you still need help or not? I’ll be glad to edit my solution. Speedmask 661 — 2y

2 answers

Log in to vote
0
Answered by
Speedmask 661 Moderation Voter
2 years ago
Edited 2 years ago

expanding on @MacGames007’s answer, I see you’ve stated that it was laggy. that’s because you are using while wait() do. please NEVER do that. it goes almost half as fast as you could actually go. if you are doing something really fast then find out how to use RunService. in this case, I would use RunService.Heartbeat.

nonetheless, I personally suggest that you use AlignOrientation. you won’t even have to use loops. just add attachment0 to the player and attachment1 to the pet. as the name suggests, pet aligns itself to the player’s orientation automatically, plus you can change the rotation speed and more. if you want to rotate instantly then turn RigidityEnabled on.

0
Hey, I couldn't figure it out from what you said, would you be able to give me an example of some sort or even just fixing my script? NotchBoy246 4 — 2y
Ad
Log in to vote
1
Answered by 2 years ago

i would recommend using something like, pet.Orientation = char.HumanoidRootPart.Orientation you know

0
I tried what you said and it works but it's very stuttery/laggy NotchBoy246 4 — 2y

Answer this question