Skip to content

Instantly share code, notes, and snippets.

@evaera
Last active July 8, 2023 06:22
Show Gist options
  • Select an option

  • Save evaera/735f23c67c2c173cfed2955f357b03a3 to your computer and use it in GitHub Desktop.

Select an option

Save evaera/735f23c67c2c173cfed2955f357b03a3 to your computer and use it in GitHub Desktop.

Revisions

  1. evaera revised this gist Oct 21, 2020. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions arrow-adornment.md
    Original file line number Diff line number Diff line change
    @@ -7,6 +7,8 @@

    Quick and dirty. You probably want this for debugging, so just slap this function in wherever you want it.

    Minified and full versions are included below. Pick one!

    ## Usage

    Call the arrow function to create an arrow in workspace. If you call the function twice with the same name, the second call will replace & reuse the original. This works well when calling from within a Heartbeat event listener to update the arrow every frame.
  2. evaera revised this gist Oct 21, 2020. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions roblox-arrow-adornment-minified.lua
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    local function arrow(b,c,d,e,f)e=e or BrickColor.random().Color;f=f or 1;if typeof(c)=="Instance"then if c:IsA("BasePart")then c=c.CFrame elseif c:IsA("Attachment")then c=c.WorldCFrame end;if d~=nil then c=c.p end end;if typeof(d)=="Instance"then if d:IsA("BasePart")then d=d.Position elseif d:IsA("Attachment")then d=d.WorldPosition end end;if typeof(c)=="CFrame"and d==nil then local g=c.lookVector;d=c.p;c=d+g*-10 end;if d==nil then d=c;c=d+Vector3.new(0,10,0)end;assert(typeof(c)=="Vector3"and typeof(d)=="Vector3","Passed parameters are of invalid types")local h=workspace:FindFirstChild("Arrows")or Instance.new("Folder")h.Name="Arrows"h.Parent=workspace;local i=h:FindFirstChild(b.."_shaft")or Instance.new("CylinderHandleAdornment")i.Height=(c-d).magnitude-2;i.CFrame=CFrame.lookAt((c+d)/2-(d-c).unit*1,d)if i.Parent==nil then i.Name=b.."_shaft"i.Color3=e;i.Radius=0.15;i.Adornee=workspace.Terrain;i.Transparency=0;i.Radius=0.15*f;i.Transparency=0;i.AlwaysOnTop=true;i.ZIndex=5-math.ceil(f)end;i.Parent=h;local j=h:FindFirstChild(b.."_head")or Instance.new("ConeHandleAdornment")f=f==1 and 1 or 1.4;if j.Parent==nil then j.Name=b.."_head"j.Color3=e;j.Radius=0.5*f;j.Transparency=0;j.Adornee=workspace.Terrain;j.Height=2*f;j.AlwaysOnTop=true;j.ZIndex=5-math.ceil(f)end;j.CFrame=CFrame.lookAt((CFrame.lookAt(d,c)*CFrame.new(0,0,-2-(f-1)/2)).p,d)j.Parent=h;if f==1 then arrow(b.."_backdrop",c,d,Color3.new(0,0,0),2)end end
  3. evaera revised this gist Oct 21, 2020. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion arrow-adornment.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    # Roblox Arrows for 3D Visualizations

    ![Demo gif](https://i.eryn.io/2043/ezgif-3-d70ddeaac0db.gif)
    ![ezgif-3-d70ddeaac0db](https://user-images.githubusercontent.com/2489210/96775967-5078c600-13b6-11eb-9662-2957be0a2953.gif)


    ## Installation

  4. evaera revised this gist Oct 21, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion arrow-adornment.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # Roblox Arrows for 3D Visualizations

    ![Demo gif](https://i.eryn.io/2043/y1xBLRlo%20%281%29.gif)
    ![Demo gif](https://i.eryn.io/2043/ezgif-3-d70ddeaac0db.gif)

    ## Installation

  5. evaera revised this gist Oct 21, 2020. 2 changed files with 14 additions and 14 deletions.
    2 changes: 1 addition & 1 deletion arrow-adornment.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # Roblox Arrows for 3D Visualizations

    <img src="https://i.eryn.io/2043/a097a82129d5.gif" />
    ![Demo gif](https://i.eryn.io/2043/y1xBLRlo%20%281%29.gif)

    ## Installation

    26 changes: 13 additions & 13 deletions roblox-arrow-adornment.lua
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    local function arrow(name, from, to, color, scale)
    color = color or BrickColor.random().Color
    scale = scale or 1
    color = color or BrickColor.random().Color
    scale = scale or 1

    if typeof(from) == "Instance" then
    if from:IsA("BasePart") then
    @@ -36,11 +36,11 @@ local function arrow(name, from, to, color, scale)

    assert(typeof(from) == "Vector3" and typeof(to) == "Vector3", "Passed parameters are of invalid types")

    local container = workspace:FindFirstChild("Arrows") or Instance.new("Folder")
    container.Name = "Arrows"
    container.Parent = workspace
    local container = workspace:FindFirstChild("Arrows") or Instance.new("Folder")
    container.Name = "Arrows"
    container.Parent = workspace

    local shaft = container:FindFirstChild(name .. "_shaft") or Instance.new("CylinderHandleAdornment")
    local shaft = container:FindFirstChild(name .. "_shaft") or Instance.new("CylinderHandleAdornment")

    shaft.Height = (from - to).magnitude - 2

    @@ -63,9 +63,9 @@ local function arrow(name, from, to, color, scale)

    shaft.Parent = container

    local pointy = container:FindFirstChild(name .. "_head") or Instance.new("ConeHandleAdornment")
    local pointy = container:FindFirstChild(name .. "_head") or Instance.new("ConeHandleAdornment")

    scale = scale == 1 and 1 or 1.4
    scale = scale == 1 and 1 or 1.4

    if pointy.Parent == nil then
    pointy.Name = name .. "_head"
    @@ -80,9 +80,9 @@ local function arrow(name, from, to, color, scale)

    pointy.CFrame = CFrame.lookAt((CFrame.lookAt(to, from) * CFrame.new(0, 0, -2 - ((scale-1)/2))).p, to)

    pointy.Parent = container
    if scale == 1 then
    arrow(name .. "_backdrop", from, to, Color3.new(0, 0, 0), 2)
    end
    pointy.Parent = container
    if scale == 1 then
    arrow(name .. "_backdrop", from, to, Color3.new(0, 0, 0), 2)
    end
    end
  6. evaera revised this gist Oct 21, 2020. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion arrow-adornment.md
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,15 @@
    # Roblox Arrows for 3D Visualizations

    <img src="https://i.eryn.io/2043/ezgif-3-a01c101b9831.gif" />
    <img src="https://i.eryn.io/2043/a097a82129d5.gif" />

    ## Installation

    Quick and dirty. You probably want this for debugging, so just slap this function in wherever you want it.

    ## Usage

    Call the arrow function to create an arrow in workspace. If you call the function twice with the same name, the second call will replace & reuse the original. This works well when calling from within a Heartbeat event listener to update the arrow every frame.

    - `arrow(name: string, from: Vector3, to: Vector3)` -> Creates an arrow between `from` and `to`
    - `arrow(name: string, point: Vector3)` -> Creates an arrow pointing at `point`
    - `arrow(name: string, cframe: CFrame)` -> Creates an arrow with its point at the CFrame position facing the CFrame LookVector
  7. evaera revised this gist Oct 21, 2020. 1 changed file with 6 additions and 7 deletions.
    13 changes: 6 additions & 7 deletions arrow-adornment.md
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,12 @@
    # Roblox Arrows for 3D Visualizations

    <img src="https://i.eryn.io/2043/y1xBLRlo.gif" />
    <img src="https://i.eryn.io/2043/ezgif-3-d6972d3dac19.gif" />
    <img src="https://i.eryn.io/2043/ezgif-3-a01c101b9831.gif" />



    ## Usage
    `arrow(name: string, from: Vector3, to: Vector3)` -> Creates an arrow between `from` and `to`
    `arrow(name: string, point: Vector3)` -> Creates an arrow pointing at `point`
    `arrow(name: string, cframe: CFrame)` -> Creates an arrow with its point at the CFrame position facing the CFrame LookVector
    `arrow(name: string, part: BasePart)` -> Arrow represents the Part's CFrame
    `arrow(name: string, fromPart: BasePart, toPart: BasePart)` -> Arrow between the two parts
    - `arrow(name: string, from: Vector3, to: Vector3)` -> Creates an arrow between `from` and `to`
    - `arrow(name: string, point: Vector3)` -> Creates an arrow pointing at `point`
    - `arrow(name: string, cframe: CFrame)` -> Creates an arrow with its point at the CFrame position facing the CFrame LookVector
    - `arrow(name: string, part: BasePart)` -> Arrow represents the Part's CFrame
    - `arrow(name: string, fromPart: BasePart, toPart: BasePart)` -> Arrow between the two parts
  8. evaera revised this gist Oct 21, 2020. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion arrow-adornment.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,8 @@
    # Roblox Arrows for 3D Visualizations

    <img src="https://i.eryn.io/2043/y1xBLRlo.gif" />
    <img src="https://i.eryn.io/2043/AF1OgkOX.gif" />
    <img src="https://i.eryn.io/2043/ezgif-3-d6972d3dac19.gif" />



    ## Usage
  9. evaera renamed this gist Oct 21, 2020. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  10. evaera revised this gist Oct 21, 2020. 2 changed files with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions roblox-arrow-adornment.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    # Roblox Arrows for 3D Visualizations

    ![Gif](https://i.eryn.io/2043/y1xBLRlo.gif)
    ![Gif](https://i.eryn.io/2043/AF1OgkOX.gif)
    <img src="https://i.eryn.io/2043/y1xBLRlo.gif" />
    <img src="https://i.eryn.io/2043/AF1OgkOX.gif" />


    ## Usage
  11. evaera created this gist Oct 21, 2020.
    88 changes: 88 additions & 0 deletions roblox-arrow-adornment-function.lua
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,88 @@
    local function arrow(name, from, to, color, scale)
    color = color or BrickColor.random().Color
    scale = scale or 1

    if typeof(from) == "Instance" then
    if from:IsA("BasePart") then

    from = from.CFrame
    elseif from:IsA("Attachment") then
    from = from.WorldCFrame
    end

    if to ~= nil then
    from = from.p
    end
    end

    if typeof(to) == "Instance" then
    if to:IsA("BasePart") then
    to = to.Position
    elseif to:IsA("Attachment") then
    to = to.WorldPosition
    end
    end

    if typeof(from) == "CFrame" and to == nil then
    local look = from.lookVector
    to = from.p
    from = to + (look * -10)
    end

    if to == nil then
    to = from
    from = to + Vector3.new(0, 10, 0)
    end

    assert(typeof(from) == "Vector3" and typeof(to) == "Vector3", "Passed parameters are of invalid types")

    local container = workspace:FindFirstChild("Arrows") or Instance.new("Folder")
    container.Name = "Arrows"
    container.Parent = workspace

    local shaft = container:FindFirstChild(name .. "_shaft") or Instance.new("CylinderHandleAdornment")

    shaft.Height = (from - to).magnitude - 2

    shaft.CFrame = CFrame.lookAt(
    ((from + to)/2) - ((to - from).unit * 1),
    to
    )

    if shaft.Parent == nil then
    shaft.Name = name .. "_shaft"
    shaft.Color3 = color
    shaft.Radius = 0.15
    shaft.Adornee = workspace.Terrain
    shaft.Transparency = 0
    shaft.Radius = 0.15 * scale
    shaft.Transparency = 0
    shaft.AlwaysOnTop = true
    shaft.ZIndex = 5 - math.ceil(scale)
    end

    shaft.Parent = container

    local pointy = container:FindFirstChild(name .. "_head") or Instance.new("ConeHandleAdornment")

    scale = scale == 1 and 1 or 1.4

    if pointy.Parent == nil then
    pointy.Name = name .. "_head"
    pointy.Color3 = color
    pointy.Radius = 0.5 * scale
    pointy.Transparency = 0
    pointy.Adornee = workspace.Terrain
    pointy.Height = 2 * scale
    pointy.AlwaysOnTop = true
    pointy.ZIndex = 5 - math.ceil(scale)
    end

    pointy.CFrame = CFrame.lookAt((CFrame.lookAt(to, from) * CFrame.new(0, 0, -2 - ((scale-1)/2))).p, to)

    pointy.Parent = container

    if scale == 1 then
    arrow(name .. "_backdrop", from, to, Color3.new(0, 0, 0), 2)
    end
    end
    12 changes: 12 additions & 0 deletions roblox-arrow-adornment.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    # Roblox Arrows for 3D Visualizations

    ![Gif](https://i.eryn.io/2043/y1xBLRlo.gif)
    ![Gif](https://i.eryn.io/2043/AF1OgkOX.gif)


    ## Usage
    `arrow(name: string, from: Vector3, to: Vector3)` -> Creates an arrow between `from` and `to`
    `arrow(name: string, point: Vector3)` -> Creates an arrow pointing at `point`
    `arrow(name: string, cframe: CFrame)` -> Creates an arrow with its point at the CFrame position facing the CFrame LookVector
    `arrow(name: string, part: BasePart)` -> Arrow represents the Part's CFrame
    `arrow(name: string, fromPart: BasePart, toPart: BasePart)` -> Arrow between the two parts