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 » Scripting Helpers
Home Search
 

[ Content Deleted ]

Previous Thread :: Next Thread 
bigbullet100 is online. bigbullet100
Joined: 14 Oct 2010
Total Posts: 1135
01 Dec 2013 02:11 PM
[ Content Deleted ]
Report Abuse
Absurdism is not online. 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
bigbullet100 is online. bigbullet100
Joined: 14 Oct 2010
Total Posts: 1135
01 Dec 2013 02:16 PM
[ Content Deleted ]
Report Abuse
BattleBloxRBX is not online. BattleBloxRBX
Joined: 27 Nov 2013
Total Posts: 69
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 is not online. 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 is not online. 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
BattleBloxRBX is not online. BattleBloxRBX
Joined: 27 Nov 2013
Total Posts: 69
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
TheNickmaster21 is not online. TheNickmaster21
Joined: 04 Oct 2008
Total Posts: 9490
01 Dec 2013 02:31 PM
@ MrNicNac

Do you really use Brackets like that?? :(
Report Abuse
Absurdism is not online. 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
bigbullet100 is online. bigbullet100
Joined: 14 Oct 2010
Total Posts: 1135
01 Dec 2013 02:35 PM
[ Content Deleted ]
Report Abuse
bigbullet100 is online. bigbullet100
Joined: 14 Oct 2010
Total Posts: 1135
01 Dec 2013 02:36 PM
[ Content Deleted ]
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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