How to make a part rotate towards the character smoothly?

Hi! So I have a spirit character that follows you around like a pet and is levitating, all the parts are cancollide off and anchored off. I have a bodyposition for the position of the spirit but for the orientation I used the standard look at cframe. It is way too jittery so is there any other way to do this?

local function Follow(HumanoidRootPart)
	BodyPosition.Position = (HumanoidRootPart.CFrame * CFrame.new(2, 2, 2)).Position
	part.CFrame = CFrame.new(part.Position, HumanoidRootPart.Position)
end

I am calling the function every 0.1 seconds instead of just wait() btw to reduce lag

If I remove line 3 it is smooth but otherwise it is jittery

Can we get also a vide, so we can see whats happening

robloxapp-20210218-1829480.wmv (3.1 MB)

Here, as you can see it is jittery due to me setting the cframe of the part every 0.1 second

you could try to use renderstep instead of a while loop

Does renderstep lag? Should I replace all while wait() loops to that?

You should use :lerp() in this case

robloxapp-20210218-1904537.wmv (1.5 MB)
I used RunService.Heartbeat but it is still jittery just not as much

you’re updating this on the client right?

No, it is on a script so it’s server sided

u can use TweenService to rotate this smoothly, did u tried that?

You should use Welds for your ‘JoJo Stands’, i’ve been working on a jojo game and we basically use welds

its because of server side lag, there will always be some latency if you’re doing stuff on the server. There is a work around though where you create the pet on the client and then send that information to the server and then back to the other clients so they can see the pet.

logic to what I mean:

  1. client (player X) fires a remote event to the server saying they have a pet equip

  2. The server is like “Hmmm ok let me see your file” and gets all the information on that specific clients pet like it’s colour, mesh, size, etc.

  3. Then the server tells everyone “Yo, player X has a pet equip with this information” and all the other clients (player Y, Z, etc) spawn a pet with player X’s pet information on player X’s position

and heres pseudo some code to get you started:

--local script
local function showPet(user) --passing the user who has the pet

    --initiates pet
    local newPet = pet:newPet(user)

end

RunService.RenderStepped:Connect(function(step)
    PetEvent:FireServer()
    showPet(player) --if the player themselves has the pet, this runs it on the client
end)

PetEvent.OnClientEvent:Connect(showPet)
--server script
-- Pet remote
local function bounceRemote(player, user)
    for i,v in ipairs(game.Players:GetPlayers()) do --getting all the players in the game

        if v ~= player then --all players BUT the one who has the pet equip, (they already ran it on the client in the earlier code at showPet(user) after PetEvent:FireServer()
            user = v
            print(user)
            PetEvent:FireClient(v, player)

        end
    end
end

PetEvent.OnServerEvent:Connect(bounceRemote)
1 Like

Wait, won’t firing the server over a runservice.renderstepped loop using a remote event lag?

oh yeah actually im dumb lol, but easy fix is to change the render stepped to this:

local function equipPet(player)
    PetEvent:FireServer()
    showPet(player) --if the player themselves has the pet, this runs it on the client
end

and just call this once whenever a player first equips their pet onto themselves. And keep the renderstepped inside your pet animation function

3 Likes