|
| 09 Jul 2015 11:04 AM |
local p1 = game.Workspace.Test local p2 = game.Workspace.Test1
while true do --creates lazer local cpie = Instance.new("Part") cpie.Parent = game.Workspace cpie.BrickColor = BrickColor.new("Teal") cpie.Material = "Neon" cpie.Transparency = .3 cpie.Name = "Lazer" cpie.Anchored = true cpie.FormFactor = "Custom" cpie.Size = Vector3.new(1,1,1) cpie.CanCollide = false --finds position local newX = (((p1.Position.X) + (p2.Position.X)) / 2) local newY = (((p1.Position.Y) + (p2.Position.Y)) / 2) local newZ = (((p1.Position.Z) + (p2.Position.Z)) / 2) --size local varA = ((p1.Position.X) - (p2.Position.X)) local varB = ((p1.Position.Y) - (p2.Position.Y)) local varC = math.sqrt(varA^2 + varB^2) cpie.Size = Vector3.new(varC,1,1)
cpie.Position = Vector3.new((newX),(newY),(newZ)) --finds angle local tangent = ((varB) / (varA)) local thingy = (math.atan(tangent)) cpie.Rotation = Vector3.new(0,0,(math.deg(thingy))) wait(.2)
cpie:remove() end
This script is meant to create a beam that connects two bricks specified at the top every so often. It works and connects when moving the bricks, but only in X and Y. I've been trying to make it work in 3 dimensions, but nothing has worked. I would appreciate help on what to do, or if there's another easier way to code it. Thanks! |
|
|
| Report Abuse |
|
rayk999
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 4705 |
|
|
| 09 Jul 2015 11:14 AM |
while true do --creates lazer local cpie = Instance.new("Part") cpie.Parent = game.Workspace cpie.BrickColor = BrickColor.new("Teal") cpie.Material = "Neon" cpie.Transparency = .3 cpie.Name = "Lazer" cpie.Anchored = true cpie.FormFactor = "Custom" cpie.CanCollide = false local cf = CFrame.new(p1.Position,p2.Position) local mag = (p1.Position-p2.Position).magnitude cpie.Size = Vector3.new(1,1,mag) cpie.CFrame = cf * CFrame.new(0,0,-mag/2) end |
|
|
| Report Abuse |
|
rayk999
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 4705 |
|
| |