| |
|
Absurdism
|
  |
| Joined: 18 Jul 2013 |
| Total Posts: 2568 |
|
|
| 01 Dec 2013 02:15 PM |
Use CFrame, it's much simpler. Adjust as you please.
local toggle = 1 script.Parent.ClickDetector.MouseClick:connect(function() toggle = toggle * -1 script.Parent.CFrame = script.Parent.CFrame * CFrame.Angles(0, 0, toggle * math.pi/3) end) |
|
|
| Report Abuse |
|
|
| |
|
|
| 01 Dec 2013 02:22 PM |
| Vector3 won't merge blocks. CFrame will. Go to the wiki and lookup CFrame for some help. |
|
|
| Report Abuse |
|
|
MrNicNac
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 26567 |
|
|
| 01 Dec 2013 02:24 PM |
"Vector3 won't merge blocks. CFrame will. Go to the wiki and lookup CFrame for some help."
Not exactly.
local p = Instance['new']([==[Part]==]) p['Position'] = Vector3['new'](0,0,0); p['Parent'] = Workspace
If a part were at 0,0,0 when that one was spawned, the part spawned would be inside the existing part because it was parented last, and positioned first. |
|
|
| Report Abuse |
|
|
Absurdism
|
  |
| Joined: 18 Jul 2013 |
| Total Posts: 2568 |
|
|
| 01 Dec 2013 02:28 PM |
It is fairly simple. You're probably confused if you're not familiar with rotation and radians. Let's analyze the script (brief, probably not sufficient):
local toggle = 1 Right now, toggle is just a variable we set to 1. We'll see what it does in a second.
script.Parent.ClickDetector.MouseClick:connect(function() This is connecting an event. It is no more the defining a function called "onClicked," or whatever you please, and connecting it to that function.
toggle = toggle * -1 Herein we multiply toggle by -1. Wait, so what does this do? Let's see what toggle is the first time we click script.Parent: toggle = 1; toggle = toggle * -1; toggle = 1 * -1 = -1 The first time, it's equal to -1. Let's analyze the second time: toggle = -1; toggle = toggle * -1; toggle = -1 * -1 = 1 Now we're back to 1. The process alternates toggle between 1 and -1.
script.Parent.CFrame = script.Parent.CFrame * CFrame.Angles(0, 0, toggle * math.pi/3) This one is a bit trickier. CFrame is short for CoordinateFrame, which is 12-element matrix; these elements are 9 rotation components and 3 position components. Rotation matrices aren't exactly simple for all people, and they can sometimes be an irritation. I have used them for discrete purposes, but I recommend avoiding them until last resort. They come to me naturally because I've used rotation matrices in different areas of mathematics. And in fact, rotation matrices are used throughout all of mathematics. We use a system of Euler angles here. Euler angles manipulate trigonometric functions in a matrix of given angles, multiply them by a spatial vector, and out comes your new rotation. If that doesn't make sense, let's look: We're multiplying by CFrame.Angles(x_angle, y_angle, z_angle). This sets the position to 0, but sets the rotation parts. So we multiply it by the original CFrame to get the desired rotation. I assumed the direction of your light-switch would be through the z-axis, but it might be through the x-axis. Imagine sticking a pole through a piece of cheese through the front and out the back, and rotating it. That is a z-rotation. Now, take that pole and stick it through and out either side of the cheese. Spin it around. That is an x-rotation. math.pi/3 is a radian system that is equivalent to 60 degrees. We multiply 60 degrees by toggle; and it either rotates -60 or 60 degrees depending on the number of times it is clicked.
end)
Ending the function here, and the connect method.
This may also be useful:
local toggle = 1 script.Parent.ClickDetector.MouseClick:connect(function() toggle = toggle * -1 script.Parent.CFrame = script.Parent.CFrame * CFrame.Angles(toggle * math.pi/3, 0, 0) end) |
|
|
| Report Abuse |
|
|
|
| 01 Dec 2013 02:29 PM |
True,
but since he'd have to end up removing the part from workspace, rotate and position the part, then move it to workspace again, it'd be much simpler to go ahead and use CFrame. |
|
|
| Report Abuse |
|
|
|
| 01 Dec 2013 02:31 PM |
@ MrNicNac
Do you really use Brackets like that?? :( |
|
|
| Report Abuse |
|
|
Absurdism
|
  |
| Joined: 18 Jul 2013 |
| Total Posts: 2568 |
|
|
| 01 Dec 2013 02:33 PM |
Yes, he does. It irritates us all. I forgot, @OP, if you want a realist light bulb, go to the store and search for one that doesn't have a religion. |
|
|
| Report Abuse |
|
|
| |
|
| |
|