Hi, I’m looking at creating a user-friendly Hotkey indicating system.
Easily description is, I wish to have a Bilboard Gui (“E”) appear over bricks of which can be interacted with. I’ve done this using several methods such as Render.Stepped etc. to indicate which is the nearest trigger.
However, I’m also trying to implement the effect of pressing E within the actual code itself, perhaps this is a mistake as this is causing fumbling and coding all over the place.
Was wondering if anybody has any other suggestions.
Personally, I’m thinking of having:
LocalScript - To indicate and recognise when a Player is close to a Trigger and to track what sort of trigger it is.
ModuleScripts - These will be the effects of pressing E.
Your best bet for tracking input once the E gui is placed is through ContextActionService, as this was its intended purpose.
You could probably organize the user’s module script to return a function, which will be binded using ContextActionService:BindAction. You could also offer a keycode option too, as well as a detection radius. It might be a lot of work though, who knows.
Tracking down bricks that should be doing magnitude checks could be done through either through a Region3 whitelist cast around the character or purely looping through an array from CollectionService:GetTagged (or similar), if small enough.
I usually limit detection intervals to something a bit larger than 1/60 of a second, like 0.3 or 0.4 seconds, that way its less performance intensive, and you would barely notice the difference.
There could be some algorithmic way of doing this where you measure the character’s distance from the maximum radius and divide that by the character’s walkspeed, use that as means for figuring out how often to check. You could also use this for detecting when the player will be outside of the area, you would just have to take its absolute value.
This would definitely work laterally, but if the player were to jump/fall, especially quickly, this would skew results! I would probably lessen this interval by the tiniest bit or only consider the X and Z axes. Then again, this shouldn’t really matter too much, so I don’t know.