Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I use surface normals to make a 'bullet mark' where a ray ends?

Asked by
zValerian 108
6 years ago
Edited 6 years ago

So I have a script that makes a mark on wherever the player clicks. However it is really glitchy and doesn't really work.

this is how it looks on the floor(where its supposed to be flat) https://gyazo.com/73c47bee3eb199b72c6568e29aa50c67

this is how it looks like on a wall(where it is supposed to be what the floor is like) https://gyazo.com/4928e30f320843d895cdf6ca46598051

Any ideas why this is happening? This is my script:

game.ReplicatedStorage.stupefyy.OnServerEvent:Connect(function(player, name, a)

local animation = game.Players:FindFirstChild(name).Character.Humanoid:LoadAnimation(game.Workspace:FindFirstChild(name).Wand.Animation)
        animation:Play()
local characterr = game.Workspace:FindFirstChild(name)
lol = Instance.new("Sound")
lol.Parent =  game.Workspace:FindFirstChild(name).Wand.Tip
lol.SoundId = "rbxassetid://2394767558"
lol.MaxDistance = 100
lol.EmitterSize = 100
lol:Play()

wait(.3)

--local ray = Ray.new(game.Workspace:FindFirstChild(name).Wand.Tip.Position(a - game.Workspace:FindFirstChild(name).Wand.Tip.Position).Unit * 750)

local character = game.Workspace:FindFirstChild(name)
local origin = character.Wand.Tip.Position


local ray = Ray.new(origin, (a - origin).Unit * 750)
local studsUporDown = 0.25
local timeTillNext = 0.025
local segmentLength = 2
local damageAmount = 10
local part = game.ReplicatedStorage.stup:Clone()
part.Parent = workspace
studsUporDown = studsUporDown * 100

local function entropy()
    local x = math.random(-studsUporDown,studsUporDown) / 50
    local y = math.random(-studsUporDown,studsUporDown) / 50
    local z = math.random(-studsUporDown,studsUporDown) / 50
  return Vector3.new(x, y, z)
end
spawn(function()
    for i = 0, 750, segmentLength do
        local Next = ray.Origin + i * ray.Direction.Unit + entropy()
    local damageRay = Ray.new(part.Position, (Next - part.Position).Unit * segmentLength)
part.CFrame = CFrame.new(Next)
    local hit, End = workspace:FindPartOnRay(damageRay, character, false, true)
if hit and hit ~= part then
        print(hit)
            local burn = game.ReplicatedStorage.hit

part:Destroy()
        part.CFrame = CFrame.new(End)
        local hum = hit.Parent:FindFirstChild("Humanoid") or hit.Parent.Parent:FindFirstChild("Humanoid")
        if hum then
            hum:TakeDamage(damageAmount)
            spawn(function()
    loll = Instance.new("Sound")
loll.Parent = hit
loll.SoundId = "rbxassetid://2394767979"
loll.MaxDistance = 100
lol.EmitterSize = 100
loll:Play()
                hum.PlatformStand = true
                wait(10)
                hum.PlatformStand = false
            end)
    else
    local burnHit = burn:Clone()
    --burnHit.CFrame = CFrame.new(End)
    burnHit.Parent = workspace
 local hit, pos, normal = game.Workspace:FindPartOnRay(ray)
burnHit.CFrame = CFrame.new(pos, pos * normal)
loll = Instance.new("Sound")
loll.Parent = burnHit
loll.SoundId = "rbxassetid://2394767979"
loll.MaxDistance = 100
lol.EmitterSize = 100
loll:Play()
        end
break
    end
        wait(timeTillNext)
    end
end)
end)

it has to do with

 local hit, pos, normal = game.Workspace:FindPartOnRay(ray)
burnHit.CFrame = CFrame.new(pos, pos + normal)
0
Is it a Decal? If so make sure it's set to show up on the FrontSurface. If it's just a MeshPart or something, you'll need to rotate it 90 degrees about the X axis or so. jakedies 315 — 6y
0
How would I do that? It is a decal on a part. zValerian 108 — 6y
0
its a thin part that has the decal and both sides. I clone it and its supposed to appear where the ray ends zValerian 108 — 6y
View all comments (2 more)
0
this is the part: https://gyazo.com/d5c2a1fee1dfbb615c0fb8aeaac9ec6a (its usually transparent but im just showing you it) the decal is on both sides. It's supposed to appear where the ray ends but this happens: https://gyazo.com/6d5683fec1e3ecb026032e23871bb177 zValerian 108 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

Use this equation for figuring out the CFrame to use: CFrame.new(pos, pos + normal) * CFrame.Angles(-math.pi/2,0,0)

0
This turns the part 90 degrees, with its FrontSurface facing the angle it came out of. zaniac10 15 — 6y
Ad

Answer this question