Advertisement
mawesome4ever

Addictedrobloxs lightning restrained to part

Jun 1st, 2017
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.15 KB | None | 0 0
  1. --[=[
  2. To see this in action, in your games console do `require(837243090):Init();`
  3.                                                                  _____KEY_______
  4.     * = brick in center of rectangle                            [Width is X Axis]
  5.                                                                 [               ]
  6.     ________                                                    [Depth is Z Axis]
  7.    |        |                                                   [_______________]
  8.    |        | Depth = 7
  9.    |        |
  10.    |   *    |  
  11.    |        |    
  12.    |        |    brick.Position = (0,0,0) ---current position of our brick
  13.    |________|     brick.Size = (4,0,4) -------the current size of our brick
  14.     --------
  15.     Width = 8
  16.    
  17.  
  18.  To get to one side, we must add the width of the rectangle divided by 2 to the
  19. position of our brick. Like so:
  20.  
  21.     brick.Position = brick.Position + Vector3.new(rectangle.Size.X/2,0,0)
  22.  
  23. Which will put our brick on the right look:
  24.  
  25.     ________                                                   
  26.    |        |                                                  
  27.    |        |
  28.    |        |
  29.    |       *|  
  30.    |        |    
  31.    |        |    brick.Position = (4,0,0) ---current position of our brick
  32.    |________|
  33.  
  34. Subtracting will have the opposite effect and put it on the left. Now how do we get
  35. to the corner? Well we add half of the depth to our bricks position Like so:
  36.  
  37.     brick.Position = brick.Position + Vector3.new(0,0,rectangle.Size.Z/2)
  38.  
  39. This would put the brick at the top right corner, If you want to put the brick insde the
  40. rectangle then you must subtract half of the brick size like so:
  41.    
  42.     brick.Position=brick.Position+Vector3.new(0,0,((rectangle.Size.Z/2)-(brick.size.Z/2)))
  43.  
  44. --------------------------------random position inside the brick:-------------------------------
  45.  
  46. To get a random position inside the rectangle create a function that will math.random the size
  47. of the part, the part is where the lightning will emit from. Once that is done return the
  48. random number as a vector3 (You would of course do this for both X and Z). Imagine i am
  49. saving what the random function returned into the variable called `randPos`, now do this to
  50. place it at a random pos in the obj:
  51.  
  52.     part.Position = Rectangle.Position+(Vector3.new(((randPos.X-Rectangle.Size.X)+(Rectangle.Size.X/2)),0,((randPos.Z-Rectangle.Size.Z)+(Rectangle.Size.Z/2)))-Vector3.new(0,part.Size.Y/2,0))
  53.  
  54. --]=]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement