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

my guess would be you don’t have IgnoreGuiInset on the crosshair gui

yes I can add an example place to the original post

What if you let devs add dynamic UIs to anchored relative to the crosshair? (if you move or resize the crosshair, the UI moves) It may be useful for stuff like ‘ammo count’.

I’m having some trouble understanding, can you show me what you mean?

Like, you could create a ‘Frame’ object with UI objects inside anchored to the crosshair position, It also moves when you change crosshair size.

Small Update


New

Hide the crosshair with:

DynamicCrosshair.hidden = true

Unlike DynamicCrosshair:Disable() this will not stop the :Update() function (useful for functions like :Raycast() when the crosshair is invisible)


Shove the crosshair with :Shove()
Usage:

DynamicCrosshair:Shove()

This will shove the crosshair by whatever your IncreasePerSecond is set as


Set the “spread” values manually:

DynamicCrosshair.Spreading.Spread = 20 -- current spread of crosshair
DynamicCrosshair.Spreading.MaxSpread = 60
DynamicCrosshair.Spreading.MinSpread = 20
DynamicCrosshair.Spreading.DecreasePerSecond = 40
DynamicCrosshair.Spreading.IncreasePerSecond = 30


Documentation Status: Not Updated :x: - I’ll get to it… eventually
If you find any bugs or glitches reply to this post!

Download here: https://www.roblox.com/library/10629104729/DynamicCrosshair

2 Likes

I tried to use the Shove() but it’s not working and stays completely still so I used SetSmooth() but yeah the Crosshair won’t last long:

Any errors? If not I’m not sure why :Shove wouldn’t work.
Make sure you have the latest version of dynamic crosshair

Hello! I currently have an issue. How would I fix this weird bug when I spam the smoothset function?

Here is a simple code that I made

local Module = require(game:GetService("ReplicatedStorage").DynamicCrosshair)

local Crosshair = Module.New(game.Players.LocalPlayer.PlayerGui:WaitForChild("Crosshair"), 5, 50, 1, 1, false)

Crosshair:Enable()
Crosshair:FollowMouse(false)

local Spread = 5
local NormalSpread = 5

game:GetService("UserInputService").InputBegan:Connect(function(Input, G)
	if G then return end
	if Input.UserInputType == Enum.UserInputType.MouseButton1 then
		Crosshair:SmoothSet(Spread + 25, 0.2)
		Spread += 25
		task.delay(0.2, function()
			Crosshair:SmoothSet(NormalSpread, 0.2)
			Spread = NormalSpread
		end)
		
		local M = math.random(1,2)
		
		if M == 1 then
			Crosshair:Hitmarker(false, 0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
		else
			Crosshair:Hitmarker(true, 1.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
		end
	end
end)

Also, I suggest making a setting that will always return the spread to the default value that you set in creating a new crosshair

Is it possible to add a borderpixel to the CenterDot?

Yes,

DynamicCrosshair.CenterDot.centerdot.BorderSizePixel = 1

UPDATE


Bug fixes with :Destroy()

Always looking for feedback
I want to expand this module as much as I can!

Showcase

Use of the normal and image crosshair using DynamicCrosshair


Reply to this post with any feature requests or bugs

3 Likes

Wow, this is still getting updated and maintained, amazing module!

Hi, this module is amazing, and I am extremely thankful that you made this. However, I did notice a bug with the Raycast() function. I was implementing it into my game, and I realized that the ray shoots above where the crosshair is. So, I did some experimenting on a completely fresh baseplate with the code you provided on your Github and had the same issue. Also, I made sure I was using the latest version and had IgnoreGuillinset on (everything else was the same).

Here are a few examples of what I mean:
Place1 - Roblox Studio (gyazo.com)
Place1 - Roblox Studio (gyazo.com)

Try turning off IgnoreGuiInset and see if that fixes your issue

I’ve tried that, it does what you expect it would. Crosshair moves down, and the ray shoots at the same position.

Hello, not sure if it’s me doing something wrong, or theres an issue wit the module

I have seperate script that creates the UI and enables it

local UI:ScreenGui = script.Parent 
local DynamicCrosshair = require(game:GetService("ReplicatedStorage").Modules.DynamicCrosshair).New(UI)
DynamicCrosshair:Enable()
--Just like in the tutorial

And then another local script that shoves the croshair when the gun shoots:

local DynamicCrosshair = require(game:GetService("ReplicatedStorage").Modules.DynamicCrosshair)
DynamicCrosshair:Shove()

But for some reason I’m getting this error:

ReplicatedStorage.Modules.DynamicCrosshair:231: attempt to index nil with 'Spread'

If you know the fix please let me know :grinning:

Maybe make a variable that determines if crosshair is changing or not and if its changing then it will cancel the task?

you can do this with simple scripting. just set the position of the gui to the position of the side of the crosshair you want + the offset you want it to be