What I mean is, imagine you have a block far far away, what would be the best way to detect whether my mouse runs over that block or something like that?
Any help will do, thanks!
You can use the properties within the players mouse to get things like this. Some useful properties and methods for getting the mouse are as follows:
- The position of where the mouse is pointing.
- The current object the mouse is over. If the mouse is not over anything, this property is nil
- The surface of the mouse's target that it is hitting.
- If set, the TargetFilter and its descendants will be ignored when determining which part the mouse is pointing to.
- The 2-Dimensional X Position of the mouse on the screen
- The 2-Dimensional Y Position of the mouse on the screen
Click here for more properties
In order to get the mouse, you need to first find the player whose mouse you are attempting to get. We can do that multiple ways, but here are just a couple common methods:
local Mouse = game.Players.LocalPlayer:GetMouse()
game.Players.PlayerAdded:connect(function(Player) local Mouse = Player:GetMouse() end)
If you have any further problems/questions, please leave a comment below, and I'll see what I can do. Hope I helped :P
You can raycast using the player's mouse's position (which you can get using the UserInputService, specifically the InputBegan/InputChanged/InputEnded events) with the method Camera.ScreenPointToRay.
A downside to this method is that you will not be able to detect blocks that are further than 1000 studs away (or 999.5 if you want to be safe from rounding errors - otherwise Roblox may complain that it's magnitude is greater than 1000).
An advantage of this method is that you can manipulate the ray and raycast in different directions (ex 1 degree to the left), if for some reason you want/need to do this.