What do I want to achieve?
An aiming system for an isometric game, are there better ways to achieve this?
What is the issue?
Aiming stutters when cursor is placed above and below the player.
What solutions have you tried so far?
Tried making HumanoidRootPart face the cursor. Not much luck as it stutters quite a bit.
local input = game:GetService("UserInputService")
local tween = game:GetService("TweenService")
local run = game:GetService("RunService")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local root_part = character:FindFirstChild("HumanoidRootPart")
local function aim_mechanism()
local mouse = player:GetMouse()
local root_pos, mouse_pos = root_part.Position, mouse.Hit.Position
local new_pos = Vector3.new(mouse_pos.X, root_pos.Y, mouse_pos.Z)
local aim_tweenInfo = TweenInfo.new(0.2, Enum.EasingStyle.Sine)
local goal = {CFrame = CFrame.new(root_pos, new_pos)}
local aim_tween = tween:Create(root_part, aim_tweenInfo, goal)
aim_tween:Play()
print(mouse_pos)
end
run.RenderStepped:Connect(aim_mechanism)
--local input = game:GetService("UserInputService")
--local tween = game:GetService("TweenService")
local run = game:GetService("RunService")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local root_part = character:FindFirstChild("HumanoidRootPart")
local function aim_mechanism()
local mouse = player:GetMouse()
local root_pos, mouse_pos = root_part.Position, mouse.Hit.Position
local new_pos = Vector3.new(mouse_pos.X, root_pos.Y, mouse_pos.Z)
--local aim_tweenInfo = TweenInfo.new(0.2, Enum.EasingStyle.Sine)
local goal = CFrame.lookAt(root_pos, new_pos, root_part.CFrame.UpVector)
root_part.CFrame = root_part.CFrame:lerp(goal, 0.1)
--[[local aim_tween = tween:Create(root_part, aim_tweenInfo, goal)
aim_tween:Play()]]
--print(mouse_pos)
end
run.RenderStepped:Connect(aim_mechanism)
Itβs smoother now but it still has that issue of not working when the cursor is placed near the player. Is there a way for the player to look at the position of the cursor on the screen?
I think it is because of the Isometric perspective, a solution I can think of is make it so it only works if it is a certain distance from the player.
UPDATE: Itβs somehow been solved after I put the script you provided into the same script as my camera script for some reason, not really sure why that happens.
local input = game:GetService("UserInputService")
local tween = game:GetService("TweenService")
local run = game:GetService("RunService")
-- βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
-- βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
-- (CAMERA SETTINGS)
local cam = workspace.CurrentCamera
local camFOV = Instance.new('IntValue')
camFOV.Value = 15
local camdp = 60
local Yoffset = 2
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local root_part = character:FindFirstChild("HumanoidRootPart")
-- (CAMERA MODULE)
local function isoCamera()
cam.FieldOfView = camFOV.Value
if root_part then
local rootPos = root_part.Position + Vector3.new(0, Yoffset, 0)
local camPos = rootPos + Vector3.new(camdp, camdp, camdp)
cam.CFrame = CFrame.lookAt(camPos, rootPos)
end
end
-- (ZOOM CONTROLS)
input.InputChanged:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseWheel then
local goal = {}
local zoom_diff = input.Position.Z * 2.5
local zoom_proc = camFOV.Value - zoom_diff
goal.Value = math.clamp(zoom_proc, 10, 20)
print(camFOV.Value)
local smoothInfo = TweenInfo.new(
.025,
Enum.EasingStyle.Quad,
Enum.EasingDirection.InOut
)
local zoom_smooth = tween:Create(camFOV, smoothInfo, goal)
zoom_smooth:Play()
end
end)
local function aim_mechanism()
local mouse = player:GetMouse()
local root_pos, mouse_pos = root_part.Position, mouse.Hit.Position
local new_pos = Vector3.new(mouse_pos.X, root_pos.Y, mouse_pos.Z)
local end_pos = CFrame.lookAt(root_pos, new_pos, root_part.CFrame.UpVector)
root_part.CFrame = root_part.CFrame:lerp(end_pos, 0.1)
end
run.RenderStepped:Connect(aim_mechanism)
run.RenderStepped:Connect(isoCamera)