generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Beam between 2 bricks in 3 dimensions [Help]

Previous Thread :: Next Thread 
HeirOfDarkness is not online. HeirOfDarkness
Joined: 01 Jul 2015
Total Posts: 2
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 is not online. 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 is not online. rayk999
Joined: 18 Feb 2011
Total Posts: 4705
09 Jul 2015 11:20 AM
oopsies i forgot a wait()
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image