I need the player to face a part like this game for example
But this is the result im getting
Here is the Code
I need the player to face a part like this game for example
But this is the result im getting
Here is the Code
Replace
while wait() do
end
with
game:GetService("RunService").RenderStepped:Connect(function()
end)
In a LocalScript
I did this by memory on my phone, so…
theres no difference tho its basically the same code, still jittery
RenderStepped is faster than while wait, but it really is still sudden. Maybe try lerp or tweenservice. I don’t know how to use lerp though.
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()
local function QuaternionMultiplication(Q1,Q2)
local a1 = Q1[1]
local a2 = Q2[1]
local v1 = Q1[2]
local v2 = Q2[2]
local Q3 = {a1*a2-v1:Dot(v2),a1*v2+a2*v1+v1:Cross(v2)}
return Q3
end
local function QuaternionAngleAxis(Axis, Angle, Vector)
if Axis.Magnitude == 0 then
warn("Unable To Rotate Around Vector With Magnitude Of Zero")
return Vector
end
Angle = -Angle/2
Axis = Axis.Unit
local Cos = math.cos(Angle)
local Sin = math.sin(Angle)
local Q = {Cos,Axis*Sin}
local U = {0,Vector}
local Qp = {Cos,Axis*-Sin}
local QU = QuaternionMultiplication(Q,U)
local QUQp = QuaternionMultiplication(QU,Qp)
return QUQp[2]
end
local Part = Instance.new("Part") -- the part to be rotated
Part.Parent = workspace
Part.Anchored = true
Part.Position = Vector3.new(0,4,0)
local Rate = math.rad(90) -- Degrees per second
RunService.RenderStepped:Connect(function(DT)
local Current = Part.CFrame.LookVector.Unit
local Goal = (Mouse.Hit.Position-Part.Position).Unit
local Axis = Goal:Cross(Current)
local AngleBetween = math.acos(math.min(Current:Dot(Goal),1))
local Rotation = math.clamp(Rate*DT,0,AngleBetween)
local NewVector = QuaternionAngleAxis(Axis,Rotation,Current)
Part.CFrame = CFrame.lookAt(Part.Position,Part.Position+NewVector)
end)
you can just up the rate and then remove the Y component of the Goal and Current vector and this should work fine, just make sure to normalized the vectors after you remove the Y component, also set the part to the humanoidrootpart
You can use AngularVelocity for this I believe. If you constantly update the CFrame it will appear fine on the server view, but the client will see it as incredibly choppy.
For AngularVelocity, I assume you can do something like this:
while wait() do
AngularVelocity.CFrame = HumanoidRootPart.CFrame
end
AngularVelocity from what i’ve experimented with will make things way smoother. No matter how it is scripted. Even in while loops it is still incredibly smooth.
Edit: The only thing you have to do is give your character an AngularVelocity instance and put it inside your HumanoidRootPart, and then assign Attachment0 to an attachment in your HumanoidRootPart. Though you might be able to assign it to the Root itself, I may be wrong. It’s been some time since i’ve used angular velocity. But I do assure you it works very well.