[v1.5] Create Dynamic Crosshairs! (Updated!)

Found this documentation bug if i’m pretty sure but smooth set enum is duplicated and incorrectly named, or was it intended to be like that?

also smooth set now doesn’t tween whenever i try to use it and uses default set, Do i need to use some functions in order to make it work or missing something here?

localscript
local rep = game:GetService('ReplicatedStorage')
local UI : ScreenGui = script.Parent 
local DynamicCrosshair = require(rep:WaitForChild('DynamicCrosshair')).New(UI, 40, 80, 30, 30)
local playerSV = game:GetService("Players")
local clientPL = playerSV.LocalPlayer
local mouse = clientPL:GetMouse()

local uis = game:GetService('UserInputService')
DynamicCrosshair:Enable()
--DynamicCrosshair:Set(40)
DynamicCrosshair:Size(30, 6)

DynamicCrosshair.ImageCrosshair.enabled = true
DynamicCrosshair.ImageCrosshair.Image = "rbxassetid://10281651490"
--DynamicCrosshair:Display({
--	BackgroundTransparency = 0; 
--	BorderSizePixel = 0;
--	Image = nil;
--	ImageTransparency = 0;
--	BackgroundColor3 = Color3.new(1, 1, 1);
--})

DynamicCrosshair.EasingStyle = Enum.EasingStyle.Bounce -- default: linear
DynamicCrosshair.EasingDirection = Enum.EasingDirection.Out -- default: InOut

-- DynamicCrosshair:SmoothSet(Spread, Transition Seconds, Update Minimum Radius When Completed)



DynamicCrosshair.CenterDot.enabled = true
DynamicCrosshair.CenterDot.size = UDim2.fromOffset(5,5)

mouse.Button1Down:Connect(function()
	DynamicCrosshair:SmoothSet(60, 0, false)
end)

What seems to be a small mistake in the documentation thanks for pointing that out :sweat_smile:

Now for your :SmoothSet(), you have the seconds parameter set to 0 meaning it won’t have the “bounce/smooth effect”. To change this just set this to seconds parameter to something to your liking such as

-- :SmoothSet(spread, seconds, updateMin)
:SmoothSet(60, 1) -- will take 1 second to "bouncingly " set

If you have any other problems or this doesn’t work for you reply to this message!

But that’s not what i expected it to do aswell, all it does for me is the delay from input (though i set the second to 1 but it still doesn’t tween)

could you shoot me a private message so we could further talk about this? Possibly with a place file and make sure the module is updated. Sorry for the inconvenience

Would you advise against using the module in that case?

I’ve actually updated the module to be more performant. I’ve used it in plenty of games and its very light-weight.

1 Like

This is amazing, you are guaranteed a spot in heaven, This module is very easy to use as well.

Their seems to be a slight offset in the mouse location and the crosshair location tho
image
It was a quick fix just added:

- UDim2.new(0, 0, 0, self.SizeX*3.5)

on line {239, 240, 241, 242, 243}


In the main module script

1 Like

Perhaps this is a result of the ScreenGui having IgnoreGuiInset off?

No I don’t think this is related to GuiInset, was about to reach into dms to get this fixed but found where it just gets off where there is already an rendered crosshair.

I simply change it’s offset in the module after spotting it

Huh interesting, thanks for reporting this ill look for a fix for this

Hi! I have recently discovered this module and thought it would be a great addition to my game. I made a quick gun using it and it went perfectly fine. Then I put it in my project but I keep getting this error and I don’t know why.

It’s in the Module Script right here

I tried setting the ‘Resolution’ to a UDim2 with the AbsoluteSize of the GUI in it but it didn’t seem to work. Any ideas on why this is happening?

Could you provide me with some code examples so I can further help you out more?

Thanks for replying. I decided to not implement a dynamic crosshair into my game. I’m still curious about this error though. Here’s the code:

As you can see I haven’t added anything to it. Still doesn’t work somehow.

This is the only LocalScript, the module is in the Replicated Storage.

Your referencing your “UI” to your tool, rather than a ScreenGui. Remember the UI has to be a ScreenGui.

1 Like

Slight problem with follow mouse…
image
It appears to not be exactly following my mouse, even when IgnoreGuiInset is on.

Whenever I try to use :Raycast it returns nan nan nan.

It should be fixed, sorry for the inconvenience.

could you provide some context? (situation, examples, code, etc)

So whenever I would use :Shove() and then :Raycast(), the raycast would return nan nan nan, nan nan nan and I have no idea why as it worked previously when I first tried it out (this time I used it for my OTS gun system.) I fixed it by doing :Shove() after :Raycast() but I feel like it’s a pretty bad workaround. Also I have a function that when called in a module changes the spread per second and maximum, however every time I :Shove() it spreads to the max (even when 0).

Code:
Gui Module

local TweenService = game:GetService("TweenService")

local Gui = {}

local TweenProp = TweenInfo.new(0.2, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)

-- Main Part

local Player = game.Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
local Display = PlayerGui:WaitForChild("ApolloGUI")

function Gui:Toggle(bool: boolean)
	Display.Enabled = bool
end

-- Crosshair Part

local DynamicCrosshair
if not DynamicCrosshair then
	DynamicCrosshair =
		require(game:GetService("ReplicatedStorage").ApolloShared.Modules.DynamicCrosshair).New(Display.Crosshair)
	DynamicCrosshair:Disable()

	DynamicCrosshair:Display({
		BackgroundTransparency = 0,
		BorderSizePixel = 1,
		Image = nil,
		ImageTransparency = 0,
		BackgroundColor3 = Color3.fromRGB(255, 255, 255),
	})

	DynamicCrosshair:Size(8, 1)
	DynamicCrosshair.Spreading.IncreasePerSecond = 1
end

function Gui:SetupSpread(Module)
	DynamicCrosshair.Spreading.IncreasePerSecond = Module.Spread
	DynamicCrosshair.Spreading.Max = Module.MaxSpread
end

function Gui:ToggleCrosshair(bool: boolean)
	if bool then
		DynamicCrosshair:Enable()
	else
		DynamicCrosshair:Disable()
	end
end

function Gui:Raycast()
	local Origin, Direction = DynamicCrosshair:Raycast()

	return Origin, Direction
end

function Gui:Recoil()
	DynamicCrosshair:Shove()
end

return Gui

If you know how to fix this it would be appreciated.