Ad
Log in to vote
0

How would you visualize a raycast (laser/bullet)?

Asked by 14 days ago
local replicatedStorage = game:GetService("ReplicatedStorage")
local weaponRemoteEvents = replicatedStorage.remoteEvents.weaponRemoteEvents

weaponRemoteEvents.shootEvent.OnServerEvent:Connect(function(player, mousePos, bulletTravelDistance, toolHandle, damage, toolName)
    local rayParams = RaycastParams.new()
    rayParams.FilterDescendantsInstances = {player.Character}
    rayParams.FilterType = Enum.RaycastFilterType.Blacklist

    local ray = workspace:Raycast(toolHandle.CFrame.p, (mousePos - toolHandle.CFrame.p) * bulletTravelDistance, rayParams)

    if ray then
        local model = ray.Instance:FindFirstAncestorOfClass("Model")
        if model then
            if model:FindFirstChild("Humanoid") then
                model.Humanoid.Health -= damage
            end
        end
    end
end)

Here is the code for the gun. I've tried so many ways to get a working visualizer but I just can't seem to get it to work. Please help. Also here are what the params are:

player = local player
mousePos = player:GetMouse().Hit
bulletTravelDistance = 300
toolHandle = toolHandle part
damage = 10
toolName = ar

1 answer

Log in to vote
0
Answered by
sayer80 457 Moderation Voter
14 days ago
Edited 14 days ago
  1. Get the Startpoint and Hitpoint
  2. Get the Middle of the 2 Points
  3. Create a Part with the length of the distance of the 2 points (Magnitude)
  4. Get the Rotation of the 2 Points

Look up everything that you don't know how to do

the second thing Is maybe :Lerp 0.5 or something

0
isn't lerp deprecated? maybe just subtract the startpoint by half of the hitpoint 0hsa 119 — 14d
0
I believe :Lerp() was to be deprecated in the context of animation, with the replacement being tweens. Vinceberget 1269 — 14d
0
local middlePos = Part1.Position:Lerp(Part2.Position, 0.5) but there is also a more efficient solution sayer80 457 — 12d
Ad

Answer this question