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

Intro
Hey :wave:, Towphy here. I just finished a quick project of mine consisting of Dynamic Crosshairs! I couldn’t find many resources on how to create a crosshair online so I decided to give the internet this module!

Function List
DynamicCrosshair.new()
DynamicCrosshair:Enable()
DynamicCrosshair:Disable()
DynamicCrosshair:Lock()
DynamicCrosshair:Size()
DynamicCrosshair:Destroy()
DynamicCrosshair:Display()
DynamicCrosshair:Set()
DynamicCrosshair:SmoothSet()
DynamicCrosshair:Shove()
DynamicCrosshair:Hitmarker()
DynamicCrosshair:Raycast()
DynamicCrosshair:FollowMouse()

▬▬▬▬▬▬▬▬

Usage

Click Here

Create crosshairs for any use such as guns, weapons, and more!

Visualize your crosshair however you please, with functions such as:
:Size() and :Display()

Control how your crosshair moves, with functions such as:
:Set(), :SmoothSet(), and :Shove()

image image image

▬▬▬▬▬▬▬▬

Documentation: DynamicCrosshair Documentation
:warning: ^ Just Released Go Check out ^ :warning:
▬▬▬▬▬▬▬▬

Module
GET THE MODULE HERE:

▬▬▬▬▬▬▬▬

Reply with constructive criticism, script improvements, or errors!!

P.S. This is my first open sourced module so feel free to give suggestions :slight_smile:

If people think this module is worth working on any further, I will add more much-needed features!

▬▬▬▬▬▬▬▬
YOUTUBE SHOWCASE: https://www.youtube.com/watch?v=nKQS1XQsKuw&ab_channel=Towphy
▬▬▬▬▬▬▬▬

Newest Update: [Click Here!][v1.5] Create Dynamic Crosshairs! (Updated!) - #114 by Towphy)

109 Likes

Can you provide screenshots or videos of the module in action?

6 Likes

This looks promising but i wanted to know if this can be used with pre-made Crosshair image without creating UI in the scripts

All i see in example was created by using scripts (I don’t like creating UI inside script as it’s time consuming when it comes with fixing position)
also


why =<

7 Likes

can you please show video representation of it in action?

6 Likes

I’ll give 20 bucks and half a pack of gun for it.

5 Likes

@Froggramming @Qinrir Video and image examples are now provided! Sorry for the wait.

3 Likes

If your talking about a pre-made crosshair image such as this image found on Google:
image

, no it will not work.

Now if you have an image of 1 hair of the crosshair, yes it can work. You could do something like:

local UI : ScreenGui = script.Parent
local DynamicCrosshair = require(script.DynamicCrosshair).New(UI)
DynamicCrosshair:Enable()

DynamicCrosshair:Size(20,20)

DynamicCrosshair:Display({
	BackgroundTransparency = 1;
	Image = 'rbxassetid://8546403605';
	ScaleType = Enum.ScaleType.Fit;
})

which will have an outcome of:
image

Maybe a feature for the future of this project is turning already made crosshairs out of frames into a DynamicCrosshair!

3 Likes

How about adding a hitmarker? It would make this module much more bettter.

6 Likes

Great idea, this will be put on a list of “To-Do” for the module!

4 Likes

Turns out the Module was off-sale. Fixed it lol. My apologies.

@pankii_kust @Andrew_Hanover

4 Likes

A great module, surely any scripter who’s been in the business for more than a year would be capable of doing something like this - though I’m certain it wouldn’t be as optimised, smooth and compact as this module. It’s time-saving to say the least, awesome job!

2 Likes

glad that it worked with the image but damn sad that i cannot use one single image and hopefully there will be, since i lov using this type of crosshair
Crosshair_small

i’ll use it in my future project

3 Likes

Did a few little raycasting tests with a Sniper I made a while back!

Also, proof DyanmicCrosshair:Raycast() works correctly lol

If you are interested in the code, here ya go:

Click Here!
local RunService = game:GetService('RunService')
local UserInputService = game:GetService('UserInputService')
UserInputService.MouseIconEnabled = false

local UI = script.Parent
local DynamicCrosshair = require(script:WaitForChild('DynamicCrosshair')).New(UI)

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

DynamicCrosshair:Enable()
DynamicCrosshair:Max(120)
DynamicCrosshair:Min(60)

local function CreateBullet(ray, origin, direction)
	local intersection = ray and ray.Position or origin + direction
	local distance = (origin - intersection).Magnitude

	local bullet_clone = Instance.new("Part")
	bullet_clone.Material = Enum.Material.Neon
	bullet_clone.Size = Vector3.new(0.1, 0.1, distance)
	bullet_clone.CFrame = CFrame.new(origin, intersection)*CFrame.new(0, 0, -distance/2)
	bullet_clone.Parent = game.Workspace.Bullets	
	bullet_clone.Anchored = true
	bullet_clone.CanCollide = false
end

local function RenderStepped(dt)
	DynamicCrosshair:Update(dt)
end

local function Click()
	-- shove crosshair
	DynamicCrosshair:Shove()

	-- raycast

	local params = RaycastParams.new()
	params.FilterType = Enum.RaycastFilterType.Blacklist
	params.FilterDescendantsInstances = {Player.Character, workspace.Bullets, workspace.CurrentCamera}
	local origin, direction = DynamicCrosshair:Raycast()
	local ray = workspace:Raycast(workspace.CurrentCamera.CFrame.Position, direction*50000, params)

	CreateBullet(ray, origin, direction)	
end

RunService.RenderStepped:Connect(RenderStepped)
Mouse.Button1Down:Connect(Click)

5 Likes

Where do i put the LocalScript?

2 Likes

It’s actually a ModuleScript! You can create a local script with some examples provided in a ScreenGui.

1 Like

This is a really neat module! Good stuff!
Will the module be receiving more updates in the future, it’ll be cool to maybe have an example place with the UI will be really nice. Overall good job!

3 Likes

Is there any way I could change the easing style to make the crosshair act more like, say, the dynamic crosshair in Phantom Forces?

Expect an updated version of DynamicCrosshair soon!

To Do:

  • Easing styles
  • Hitmarkers
  • Events
  • Single-Image Support
  • Bug fixes
  • Work on overall performance
4 Likes

Update v1.1 (First Update!) :white_check_mark:

NEW:

  • Easing Styles
  • Updated Documentation

REMOVED:

  • DynamicCrosshair:Min()
  • DynamicCrosshair:Max()
  • DynamicCrosshair:SpreadPerSecond()
  • DynamicCrosshair:DecreasePerSecond()

Information:

Functions like Min(), Max(), etc have been replaced with DynamicCrosshair.Min = numberValue. DynamicCrosshair.Max = numberValue, etc to simplify the module!

[!] The function :SmoothSet() got a total rework [!]

You can now implement EasingStyles and EasingDirections inherited from Roblox’s TweenService when using SmoothSet()

SmoothSet() also got a new argument, which is UpdateMin.
The UpdateMin argument changes the crosshairs minimum spread meaning the decreasePerSecond spread won’t affect it after the SmoothSet is completed.
The UpdateMin argument will also always default to False
Alternatively, you can use DynamicCrosshair’s Lock() function which would have the same result that would look somewhat like this:

DynamicCrosshair:Lock(true)
DynamicCrosshair:SmoothSet(50,2)
task.wait(2)
DynamicCrosshair:SmoothSet(20,2)
DynamicCrosshair:Lock(false()

Showcase Example:

local RunService = game:GetService("TweenService")
local DynamicCrosshair = require(...).New(...)
DynamicCrosshair:Enable()

DynamicCrosshair.Min = 10
DynamicCrosshair.Max = 100

RunService.RenderStepped:Connect(function(dt) DynamicCrosshair:Update(dt) end)

DynamicCrosshair.EasingStyle = Enum.EasingStyle.Linear
DynamicCrosshair.EasingDirection = Enum.EasingDirection.InOut

DynamicCrosshair:SmoothSet(50--[[ spread ]], 2  --[[ seconds]], true  --[[ update min]])
DynamicCrosshair:SmoothSet(50, 2, false)

Easing Styles Showcase: [v1.1] Create Dynamic Crosshairs! (Updated!) - #23 by Towphy :white_check_mark:
Documentation Status: Not Updated :x:

If you find any bugs or glitches reply to this post!

3 Likes

You should add a toggleable option that makes it follow the mouse

also wheres the download for v1.1

1 Like