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
Update v1.1 (First Update!)
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
Documentation Status: Not Updated
If you find any bugs or glitches reply to this post!
You should add a toggleable option that makes it follow the mouse
also wheres the download for v1.1
Same model as always:
Good idea, added to the to-do list!
Easing Styles Showcase
Download Place File Here!:
DynamicCrosshair_Styles.rbxl (52.5 KB)
If you run into any issues, reply to this post!
i checked the crosshair module in the place file and the one on the model
they are not the same!
i think you forgot to update it.
Sorry for the inconvenience, should be fixed now!
Update v1.2 (Hit Markers & Follow Mouse)
NEW:
- Hit markers
- Follow mouse function
-
:Update()
handled by module
Information:
DynamicCrosshair now supports hitmarkers! Hitmarkers are totally customizable down to the image, size, fadetime, etc. It’s as simple as calling the DynamicCrosshair:HitMarker() function!
Example:
local ScreenUI = script.Parent
local Module = require(script.Parent:WaitForChild('Crosshair'))
local DynamicCrosshair = Module.New(ScreenUi)
DynamicCrosshair:Enable()
-- all settings:
-- all of these settings are optional, the hitmarker will just revert to defaults
DynamicCrosshair.HitMarker.default = Color3.new(1, 1, 1) -- color3 value
DynamicCrosshair.HitMarker.headshot = Color3.new(1, 0, 0) -- color3 value
DynamicCrosshair.HitMarker.size = Udim2.fromOffset(60,60) --udim2 value
DynamicCrosshair.HitMarker.image = "rbxassetid://285779644" -- image
DynamicCrosshair.HitMarker.fadeTime = .25 -- number value
DynamicCrosshair.HitMarker.easingStyle = Enum.EasingStyle.Linear -- easing style
DynamicCrosshair.HitMarker.easingDirection = Enum.EasingDirection.InOut
-- CALL FUNCTION
-- DynamicCrosshair:HitMarker(headshot : boolean)
DynamicCrosshair:HitMarker() -- headshot false
DynamicCrosshair:HitMarker(true) -- headshot true
DynamicCrosshair:HitMarker(false) -- headshot false
--all ways will work correctly^
Along with the inclusion of hitmarkers, the function :FollowMouse
has been added!
Example:
local ScreenUI = script.Parent
local Module = require(script.Parent:WaitForChild('Crosshair'))
local DynamicCrosshair = Module.New(ScreenUi)
DynamicCrosshair:Enable()
DynamicCrosshair:FollowMouse() -- crosshair will follow mouse
DynamicCrosshair:FollowMouse(true) -- crosshair will follow mouse
DynamicCrosshair:FollowMouse(false) -- crosshair will stop following mouse
Last to mention, the function :Update()
is now fully handled by the module for simplifying things in general. Using the :Update
function in your script might cause some unexpected bugs!
Special thanks for @HttpsTimeout for their contributions towards this update!
The documentation is currently very outdated right now, working on it!
If you want any video/image examples from this new update reply to this post
Module: DynamicCrosshair - Roblox
Im wondering how to make a zoomIn and zoomOut using these functions? so the cross hair gets smaller or bigger
When I saw this had been updated twice, I did a little happy dance in my head, especially when I noticed easing styles were added. However, when I implemented the new module, I got this error on line 197:
path.DynamicCrosshair:197: attempt to index nil with 'spread'`
It’s coming from the :SmoothSet()
function in the module. I made 100% sure by removing :SmoothSet()
from my code, and it didn’t return an error.
I am using this code from the v1.1 post.
How can I fix this? Am I doing something wrong?
Thanks,
Fizzitix
You can try to accomplish this by possibly using DynamicCrosshair’s :Display()
function? Seems like kind of a stretch so maybe a built-in function that does this exact thing can be seen in a future update.
Stay tuned for upcoming update releases!
I’ll give it a look thanks for the reply.
That documentation is outdated to my knowledge, which is at the top of my to-do list to update.
Maybe create a separate website for documentation? If it’s a good idea ~
I’ll reply as soon as I can with a fix or patch for the module!
Just ran the code and replicated the same error:
After looking into it I found out it was a capitalization problem
Silly error that should’ve been fixed a while ago
Module is update!
Download here: DynamicCrosshair - Roblox
Thanks so much! This module is super, super useful. Keep it up!
Fizzitix
Update v1.3 (Documentation Update!)
Finally, FINALLY! New DynamicCrosshair documentation hosted by GitHun Pages!
Go check it out here: Documentation
If you find any issues or problems with the website shoot me a message on discord or the devforum!
Discord: Towphy#6174
Module Updates
Update v1.3 doesn’t just include new documentation, but a few new module updates!
Hitmakers
You can now customize the hitmakers default and headshot image!
Example here:
local UI : ScreenGui = script.Parent
local DynamicCrosshair = require(script.DynamicCrosshair).New(UI)
DynamicCrosshair:Enable()
DynamicCrosshair.HitMarker.Image.default = "rbxassetid://285779644"
DynamicCrosshair.HitMarker.Image.headshot = "rbxassetid://285779644"
DynamicCrosshair:Hitmarker(true)
If the HitMarker.Image.headshot
is left nil, it will default to HitMarker.Image.default
Very minor changes to the following functions:
DynamicCrosshair:Set()
DynamicCrosshair:Lock()
DynamicCrosshair:Hitmarker()
Download The Module Here:
As always, if you run into any problems with the website or module respond to this post or reach out to me on my socials (located on the documentation website)
Hello, I am currently experiencing a problem related to :Raycast()
.
I’m not sure if it’s my coding or the module itself, but the direction it returns is inaccurate. I made sure of blacklisting character itself from the raycast, and followed the documentation well, but unfortunately, the problem still persists.
If needed, here is how my code looks like.
function FireProjectile()
local VIEWPORT_SIZE = Camera.ViewportSize
local CAST_LENGTH = Tool:GetAttribute("BulletMaxDist")
raycastParams.FilterDescendantsInstances = {Character, IgnoreList}
local _, direction = DynamicCrosshair:Raycast()
local unitRay = Camera:ScreenPointToRay(VIEWPORT_SIZE.X / 2, VIEWPORT_SIZE.Y / 2 - game:GetService("GuiService"):GetGuiInset().Y)
local raycastResult = workspace:Raycast(unitRay.Origin, direction * CAST_LENGTH, raycastParams)
local TargetPosition = if raycastResult then raycastResult.Position else unitRay.Origin + direction * CAST_LENGTH
if not isInSafeMode then
MouseEvent:FireServer(TargetPosition)
end
if RoxiteSettings.Debug then
local Line, Cone = Gizmo:DrawArrow(unitRay.Origin, TargetPosition, Color3.fromRGB(85, 186, 255))
game:GetService("Debris"):AddItem(Line, 5)
game:GetService("Debris"):AddItem(Cone, 5)
end
end
If it’s just my scripting, please correct me.
Hmm, interesting, it could possibly be because of the Camera:ScreenPointToRay
you use in your code, since DynamicCrosshair already does that for you, but I doubt it.
I’d say try it without it and see if anything changes.
try this
function FireProjectile()
local CAST_LENGTH = Tool:GetAttribute("BulletMaxDist")
raycastParams.FilterDescendantsInstances = {Character, IgnoreList}
local origin, direction = DynamicCrosshair:Raycast()
local raycastResult = workspace:Raycast(origin, direction * CAST_LENGTH, raycastParams)
local TargetPosition = if raycastResult then raycastResult.Position else origin + direction * CAST_LENGTH
if not isInSafeMode then
MouseEvent:FireServer(TargetPosition)
end
if RoxiteSettings.Debug then
local Line, Cone = Gizmo:DrawArrow(origin, TargetPosition, Color3.fromRGB(85, 186, 255))
game:GetService("Debris"):AddItem(Line, 5)
game:GetService("Debris"):AddItem(Cone, 5)
end
end
If the problem persists could you send a Roblox file so I can take a look myself? My socials are all on the documentation website!
The problem persists, nonetheless.
I can give you the file in your private message to troubleshoot the issue, whether it is my scripting or your module.
Hmm strage it seemed that the :set function caused some enormous leak when used in consecutive order every frame