Hello everyone! So i’ve made an door system with lock for my game, and there is 1 problem.
When player hovers his mouse above the door it should make a text under his mouse with the action (open, close, unlock, lock, whatever), but for mobile users there is no mouse. So what i thought about is that i should probably mkae like that so script can detect if center of the screen hovers the object, and if it does, it shows the text label with the action on it. But 1 question… How do i make it like that so i can detect is cetner of the screen hovering an object or not?
Game is in first person, so doing so is not bad i think.
I wanna make it like that so mobile users would have an action button on their screens and it would work for any object that their center of the screen hovers. How do i detect objects that are hovered by the center of the screen?
1 Like
Raycasts is your best friend in this case, it is also not that hard to learn and is generally simple to Use, you can find alot of tutorials online… and despite what everyone might say, if you want you can also try asking ChatGPT, but if possible also ask for a simple explanation on how to use it so you also learn from it
1 Like
As Herstal said, raycasts are a good way to do this and there are many resources online on how to raycast from the center of the screen/camera.
You could use tags, attributes, or names to detect if the raycast has hit something interactible. Then when the raycast hits something interactible, you could bind and unbind actions to ContextActionService (it allows you easily add an action button for the mobile users) so the player can interact with it.
1 Like
Raycasting is a possible solution, but I’ve seen many door systems, and used it myself, that uses magnitude (distance) from the door, and then you set a binding (and a button for mobile) to handle actions using ContextActionService, but it’s not the only ways to do so.
Here is an example of a door system I’ve done a few years ago, it uses ProximityPrompt instead of ContextActionService. You can adapt or use it as reference if you’d like. The code isn’t the best, although it has many comments, yet it’s an interesting example. You’d have to implement your lock/unlock system, but you can take a look at the clearance system I have there and change it to how you desire.
doorSystemExample.rbxl (72.4 KB)
Hope it helps!
1 Like
Use a raycast in the center of the screen and cast it from Camera.CFrame.Position in the Camera.CFrame.LookVector direction
1 Like
Thanks for reply, i will use raycast.
i’ve never heard about ContextActionService but it would be interesting to learn about it more, so that’s what i gonna do, thanks for mentioning it. Have a nice day!
1 Like