#How can i use fastcastredux (popular raycast moduel) with gui element ray instead of mouse

2 messages · Page 1 of 1 (latest)

grizzled ridge
#

im making a gun that uses fastcastredux moduel and i wanna add mobile support to it by adding a crosshair in the screen to shoot the gun exacly at this position, i have this script that sorta does that but the issue is its slightly unacccurate for some resson + i cant shoot the sky becuase the raycast fails, any fixes to these?

Fast Cast: https://create.roblox.com/store/asset/4453855787/FastCast-Redux?externalSource=www&assetType=Model

if theres any document or video explaning how to do a simple mobile crosshair like this please link it

#
-----SERVER SCRIPT------
local tool = script.Parent
local active = tool.activeevent
local fastcast = require(game.ServerStorage.FastCastRedux)
--fastcast.VisualizeCasts = true

local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
tool.Equipped:Connect(function()
    
    params.FilterDescendantsInstances = {tool.Parent,tool.Handle,tool.Parent:GetChildren()}
end)


active.OnServerEvent:Connect(function(plr,p1,p2)
    local bullet = game.ReplicatedStorage.Bullet.toolbullet:Clone()
    bullet.Parent = workspace

    local orgin = tool.Handle.Position
    local caster = fastcast.new()
    local dire = p2
    
    local behave = caster.newBehavior(params)
    caster:Fire(orgin,dire,150,behave)
    
    caster.LengthChanged:Connect(function(cast, last, dire, length)
        local blength = bullet.Size.Z/2
        local offset = CFrame.new(0,0,-(length-blength))    
        bullet.CFrame = CFrame.lookAt(last,last+dire):ToWorldSpace(offset)
    end)
    
    caster.RayHit:Connect(function(ray, result)
    local hit = result.Instance
    print(hit)
    local char = hit:FindFirstAncestorOfClass('Model') or hit.Parent
    if char.Name == plr.Name then return end
    local hum = char:FindFirstChild('Humanoid')
    if hum then
        hum.Health = 0
        
    end
        bullet:Destroy()
    end)
    
end)