So I am working on a custom movement system using Roblox physics (e.g. VectorForce, LinearVelocity, etc.) and so far it has been going great. Then I wanted to make the character rotate in the direction I’m moving. That’s where to problem occurs.
function movement:move()
self.moving = true
--updates direction every millisecond while moving
while self.moving == true and wait() do
--rotates character towards move direction <----- this is where I rotate the character
self:rotate_character(self:calculate_direction())
--applies less force if humanoid is in the air (prevents insane speed while in air)
if humanoid.FloorMaterial ~= Enum.Material.Air then
self.vectorforce.Force = self:calculate_direction() * self.speed
else
self.vectorforce.Force = self:calculate_direction() * (self.speed / 5)
end
end
end
My rotate_character function looks like this:
function movement:rotate_character(towards: Vector3)
if towards.Magnitude == 0 then
towards = humrootpart.CFrame.LookVector
end
local rotationinfo = TweenInfo.new(0.2, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
local rotationgoals = {CFrame = CFrame.lookAt(humrootpart.CFrame.Position, humrootpart.CFrame.Position + towards)}
--smoothly rotates character towards desired vector
tweenservice:Create(humrootpart, rotationinfo, rotationgoals):Play()
end
So my problem is the character starts bugging out, when I’m trying to rotate:
robloxapp-20241227-0043125.wmv (614.4 KB)
Without rotating:
robloxapp-20241227-0046094.wmv (833.1 KB)
As you can see without rotation everything is flawless. I’m 100% sure that the issue is tweening the CFrame of my HumanoidRootPart, while it is constantly being changed by VectorForce, which moves the character. So it basically tweens my player to a position, where it was .01 seconds ago, which creates those stutters.
I tried using AlignOrientation constraint, but that turned out crazy buggy, like my character would levitate when I tried jumping off an edge. I assume it happened, because somehow the constraint affected the position of my humanoid root part, even though I read that AlignOrientation only aligns orientation lol
With all that being said, I’m open to any solutions or ideas, maybe even tips on how to improve my logic within the system, from high iq, gifted individuals. Thanks for taking your time here!