Hey all,
Currently refactoring a lot of my game logic to support gamepad controls, one bit I need to redo is my cursor tracking logic and it seems that the InputObject data for the gamepad inputs is a lot different than the position data for mouse movements.
From what I can tell, the input position isn’t actually screen space at all, but rather a range for the sensitivity of the gyro sticks. So I’m trying to find a workaround solution by casting a ray from the camera:
-- Adjust inputPos for gamepad input
local ray = Ray.new(workspace.CurrentCamera.CFrame.Position, workspace.CurrentCamera.CFrame.LookVector * 200)
local ignore = {player.Character}
local castParams = RaycastParams.new()
castParams.FilterType = Enum.RaycastFilterType.Exclude
castParams.IgnoreWater = true
castParams.FilterDescendantsInstances = ignore
local raycastResult = workspace:Raycast(ray.Origin, ray.Direction, castParams)
if raycastResult then
local hitPosition = raycastResult.Position
local hitPositionNew = Vector3.new(
math.floor(hitPosition.X + 0.5),
math.floor(hitPosition.Y + 0.5),
math.floor(hitPosition.Z + 0.5)
)
marker.Position = hitPositionNew
This works so to speak, but the ray is going directly from the camera towards the player, so unless you’re in first person mode it’s not really tracking the actual cursor:
In the picture above, the little red square behind my head is where the market is casting too, the crosshair/cursor is where I’d like the marker to actually be.