Dynamic Interaction System and Crosshair Module | Easily create interactions

:vhs:Source Code | :ocean:Playground

Dynamic Crosshair Module/Dynamic Interaction System is a versatile module that allows developers to simply create interactions with satisfying crosshair movement. This system has an interaction system similar to that of :video_game:3008 by :bust_in_silhouette:uglyburger0 - Roblox.

đź“–Tutorial/Documentation

How to require Dynamic Crosshair Module

local DynamicCrosshair = require(script:WaitForChild("DynamicCrosshair")) -- where you keep the module

How To Use

DynamicCrosshair.New(“cursorImageID”, “DynamicCursorID”, {table}, MaxdistanceNumber)
Function that creates a new table of MODELS to do the effect on.

local DynamicCrosshair = require(script:WaitForChild("DynamicCrosshair"))

local cursorImage = "rbxassetid://9479788733"
local movingCursorImage = "rbxassetid://14375733866"

local interactableObjects = workspace:WaitForChild("Interactables"):GetChildren() -- or {models}

local dynamicCrosshair = DynamicCrosshair.New(cursorImage, movingCursorImage, interactableObjects, maxDistance)

SETTING UP CALLBACK FUNCTIONS

local dynamicCrosshair = DynamicCrosshair.New(cursorImage, movingCursorImage, interactableObjects, maxDistance)

dynamicCrosshair:SetCallbacks(
	function(object) -- mouse enter
		-- what you want to happen when the mouse enters
	end,
	function(object) -- mouse leave
		-- what you want to happen when the mouse leaves
	end,
	function(object) -- interact
		-- what you want to happen when a player interacts
	end
)

Adding in interact bindings

local dynamicCrosshair = DynamicCrosshair.New(cursorImage, movingCursorImage, interactableObjects, maxDistance)

local UserInputService = game:GetService("UserInputService")

local KeyboardKeyCode = Enum.KeyCode.E
local ConsoleKeyCode = Enum.KeyCode.ButtonX

UserInputService.InputBegan:Connect(function(input, gameProcessed)
	if not gameProcessed and (input.KeyCode == KeyboardKeyCode or input.KeyCode == ConsoleKeyCode) then
		local hoveredObject = dynamicCrosshair:Update()
		if hoveredObject then
			dynamicCrosshair.OnInputAction(hoveredObject)
		end
	end
end)

UserInputService.TouchTap:Connect(function()
	local hoveredObject = dynamicCrosshair:Update()
	if hoveredObject then
		dynamicCrosshair.OnInputAction(hoveredObject)
	end
end)

OTHER FUNCTIONS

Enabling/Disabling

local dynamicCrosshair = DynamicCrosshair.New(cursorImage, movingCursorImage, interactableObjects, maxDistance)

dynamicCrosshair:Enable() -- Enable it, when you use the .New function it auto enables
local dynamicCrosshair = DynamicCrosshair.New(cursorImage, movingCursorImage, interactableObjects, maxDistance)

dynamicCrosshair:Disable() -- Disable/Hide, it doesnt stop the Interactions

Function to add UI objects to follow the dynamic cursor

local dynamicCrosshair = DynamicCrosshair.New(cursorImage, movingCursorImage, interactableObjects, maxDistance)

dynamicCrosshair:AddFollowObject(uiobject) -- your UI object, has to be a frame or imagelabel/textlabel/buttons
🗣️Other Useful Information

→ I recommend using my base code in the example of the module because it has the input systems and precoded functions, such as text appearing, all controls for all devices, and a hold input system.

→ If you use my precoded example keep in mind the attributes you can set on an object
“HoldDuration” → Number (Time in seconds you want it to hold; 0 = no hold)
“DisplayName” → String (“Name it says when hovering”)
“InteractText” → String (“E” to “…”)

→ If you use my precoded example, if you dont change it, you can add a highlight object to use a prescripted highlight on hover. Dont have one and it wont.

→ The module only works for models, so if you have a part, make sure its parented to a model and when you pass it, pass it as the model not the part, I recommend adding a primary part to the object.

→ Dislike where the cursor lands? Move the pivot point of the model to where you want the cursor to pivot around.

→ Wanna disable an object in the table? Add a tag called “Ignore” and the system will simply ignore it, this is good for adding in cooldowns or debounces. Remove the tag and it will work again :+1:

→ The system does not allow interacting through walls.

:movie_camera:Showcases

:computer_mouse:Hover System


:door:Door Example

Credits

@JJsStuff_1 → Created the system and dev-forum

Final

Dynamic Crosshair is free and open source. If you have any questions or suggestions you can place a comment on this post. Also report bugs please :pray: :bug:

You are welcome to use and modify this module for any of your projects, credits would be greatly appreciated but not required :pray: :smile:

Please do not reupload this module unless you made changes and its not a virus.

That is the module, thank you :pray:

If you want to see another interaction system I made check out :computer_mouse:MouseCastPlus

13 Likes