#Not the results I wanted

22 messages · Page 1 of 1 (latest)

sand nexus
#

I've been making a ray laser gun recently everything works perfectly except there is a bug I'm confused with

#
local function Params()
    local raycastParams = RaycastParams.new()
    raycastParams.FilterDescendantsInstances = {tool.Parent,tool}
    raycastParams.FilterType = Enum.RaycastFilterType.Exclude
    raycastParams.IgnoreWater = true
    return raycastParams
end

tool.Activated:Connect(function()
    local player = game.Players:GetPlayerFromCharacter(tool.Parent)
    local character = player.Character
    local mousePos = Mid:InvokeClient(player)
    local params = Params()
    local direction = (Vector3.new(mousePos) - handle.Position).Unit * range
    local raycastresult = workspace:Raycast(handle.Position,direction,params)
    if raycastresult then
        print(raycastresult.Instance)
        local midpoint = (handle.Position - direction)/2
        local part = Instance.new("Part",workspace)
        part.Size = Vector3.new(0.1,0.1,direction.Magnitude)
        part.CFrame = CFrame.new(midpoint,raycastresult.Position)
        part.Color = Color3.fromRGB(255, 85, 0)
        part.Material = "Neon"
        part.Anchored = true
        part.CanCollide = false
    end
end)
#

I wanted the bullets aka parts to shoot perfectly but it gives me something like this

fallen oar
#

why is your direction multiplied by ur range

#

thats weird

#

usually direction is normalized

sand nexus
#

I fixed it

#

I remade the whole code

#

It was a mess

#

I also improved it alot

sand nexus
#

It gives the direction with the length / magnitude of 1

#

I multiplied it by the range so for example I want the range to be 100

#

The max range of the ray will be 100

fallen oar
#

yes. i know

fallen oar
#

i mean a variable named direction

#

is usually normalized

#

and is then multiplied

sand nexus