Hi so I was really curious how would I go about making something like this so the character and the camera are smoothly rotating towards the part, example in what I want to achieve is in the video
1 Like
Hey there! This is actually a quite simple task to achieve. You can use a combination of
CFrame.lookAt(), something called “Tweening”, and something called a “BodyGyro”. To do this, you can insert a LocalScript into StarterPlayerScripts, or wherever you usually put client scripts. Then just follow what I have below:
--[[VARIABLES]]--
local PLRS = game:GetService("Players") -- the players service
local TS = game:GetService("TweenService") -- tween service (used for smoothly 'Tweening' pretty much anything)
local runService = game:GetService("RunService") -- run service
--player assets--
local player = PLRS.LocalPlayer -- the player
local character = player.Character or player.CharacterAdded:Wait()
local mouse = player:GetMouse() -- getting the mouse of the player
--filtering--
local mouseTargetFiltering = {
"LookAtPart"
}
--values--
local isLookingAtPart = false
--[[FUNCTIONS]]--
local function addGyro()
local newGryo = Instance.new("BodyGyro")
newGryo.Name = "LookAtGyro"
newGryo.MaxTorque = Vector3.new(0, 0, 0)
newGryo.P = 4000
newGryo.D = 100
newGryo.Parent = character:WaitForChild("HumanoidRootPart")
end
local function tweenToPart(part)
character.HumanoidRootPart:FindFirstChild("LookAtGyro").MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
coroutine.wrap(function()
part.Color = Color3.fromRGB(53, 255, 30)
while part and isLookingAtPart == true do
TS:Create(character.HumanoidRootPart:FindFirstChild("LookAtGyro"), TweenInfo.new(.25, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0), {CFrame = CFrame.lookAt(player.Character.HumanoidRootPart.Position, part.Position * Vector3.new(1, 0, 1) + player.Character.HumanoidRootPart.Position * Vector3.new(0, 1, 0))}):Play()
task.wait()
end
part.Color = Color3.fromRGB(255, 0, 0)
character.HumanoidRootPart:FindFirstChild("LookAtGyro").MaxTorque = Vector3.new(0, 0, 0)
end)()
end
addGyro()
runService.RenderStepped:Connect(function()
if mouse.Target then
for i, filter in pairs(mouseTargetFiltering) do
if mouse.Target.Name == filter and not isLookingAtPart then
isLookingAtPart = true
tweenToPart(mouse.Target)
break
else
isLookingAtPart = false
break
end
end
end
end)
Of course you can always tweak and perfect this to your liking. This is a pretty bare-bones concept of what it would look like.
If you need further help, please don’t hesitate to respond!
I hope this does help.
Cheers,
Techy
2 Likes
Thank you so much for your help it is just how I wanted it to be, hope you have a great day or night!
1 Like
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.