Trying to make an isometric aiming system for my game, not having much luck as it stutters a lot

  1. What do I want to achieve?
    An aiming system for an isometric game, are there better ways to achieve this?

  2. What is the issue?
    Aiming stutters when cursor is placed above and below the player.

  3. 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)

2 Likes

Don’t use tweening for loops, please use Lerp instead.
You would want to also use CFrame.lookAt.

3 Likes

Can you explain please? I’m really new to Roblox Studio.

1 Like

Try using this code:

--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)

This code uses lerping and it’s quite smooth.

2 Likes

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?

EDIT: Thank you for your time.

1 Like

That’s weird. It doesn’t happen on an empty baseplate.

1 Like

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)



This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.