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
 

Re: Brick rotation

Previous Thread :: Next Thread 
ggfunny1234 is not online. ggfunny1234
Joined: 09 Jul 2010
Total Posts: 3432
06 Jul 2012 10:06 PM
Alright, I know this is a pretty stupid question for me to be asking, but here it goes:

I'm making the simplest of all rotational things. I'm making a door that rotates 90 degrees to one side. My dilemma?

It seems that the brick is rotating upon a point somewhere in the center of the brick. I want to set it (somehow) to a position on the edge of the brick, so that it rotates properly.

Here's an attempt at a visual example:

|_ -- This is what it ​>>should<< do, the underscore represents the door. However, what's happening, is this:

|-

Sorry if those are bad examples, it's kind of a difficult thing to explain.
Report Abuse
slayer9365 is not online. slayer9365
Joined: 22 Oct 2007
Total Posts: 2312
06 Jul 2012 10:25 PM
You need to not only CFrame the doors rotation, but also CFrame the doors position.
Report Abuse
wazup07 is not online. wazup07
Joined: 17 Oct 2009
Total Posts: 313
06 Jul 2012 10:29 PM
^ I was just about to say that.... Or you could always use motors or hinges. I'm not sure about your situation though if those would work best for you.
Report Abuse
ggfunny1234 is not online. ggfunny1234
Joined: 09 Jul 2010
Total Posts: 3432
06 Jul 2012 10:38 PM
Erm, no, motors and hinges are.. Well.. Crappy. Scripting works better.

@Slayer

Alright, I'll try it. Thank you.
Report Abuse
ggfunny1234 is not online. ggfunny1234
Joined: 09 Jul 2010
Total Posts: 3432
06 Jul 2012 11:01 PM
It's not working..

Here's my script:

door = script.Parent

wait(3)
for i = 0, 90, .1 do
wait(.001)
door.CFrame = CFrame.Angles(math.rad(0), math.rad(i), math.rad(0))
door.Position = Vector3.new(0, 5, 0) -- This is just to keep the door in place, since rotating it seems to move it through bricks that are around it.
end

I attempted to use a line (door.CFrame = CFrame.new(0, 5, 0) to do what you said, slayer, but it only kept the door from rotating. I'm not exactly sure how you could mean that CFraming it as well as rotating will change the point of which the door rotates.
Report Abuse
Corecii is not online. Corecii
Joined: 06 Aug 2010
Total Posts: 687
06 Jul 2012 11:06 PM
partA = script.Parent.DoorEdge --The edge to rotate around
partB = script.Parent.Door --The door itself
offset = PartB.CFrame:toObjectSpace(partA.CFrame):inverse() --This line gets the door's cframe difference from the edge.
--So, for example, if it was 7 studs to the right of the edge, it'd be the same as CFrame.new(7,0,0)
--It also does rotation and all that stuff.
--partA.CFrame*offset would be partB's current CFrame.
--If I rotate partA's CFrame and do partA.CFrame*offset, it'd 'add' seven studs to the door edge's side, not the world's.
--It's kinda like the offset property of the BlockMesh object, if you want ot view it that way.

--And also, Cframe1*CFrame2 is like adding CFrames.
--If you have a rotated CFrame (CFrame.Angles(0,math.rad(45),0)), and add (*) & studs on the x axis through CFrame (CFrame.new(7,0,0)) ...
-- ... It would move, not on the world's axis, but on the object's. It wouldn't be at the position 7,0,0; but more something like ...
-- ... 4.5,0,4.5; because it went on the object's axis, not the world's
-- toObjectSpace gets what can be used as an 'offset'
-- The only thing is, you have to use :inverse() to use the * operator with it. / would probably work, but I haven't tried it.

RotateAmount = 5 --The amount in degrees to rotate by every time

for k = 1, 90, RotateAmount do --for var = start, end, increment do --Increment is the amount to go by. 1, 90, 5 goes 5, 10 ,15, etc to 90
partA.CFrame = partB.CFrame*CFrame.Angles(0,math.rad(k),0)*offset --k will always be the amount to rotate by, since it goes 5, 10, 15, 20, etc
wait(0.03) --I like smooth moving doors, If it just appeared at the new location, it wouldn't look good.
end

partA.CFrame = partB.CFrame*CFrame.Angles(0,math.pi/2,0)*offset --Make sure it ends up how it should. This would just turns it 90 degrees (math.pi/2 = 90 degrees).


Hope it helped. CFraming can be confusing, but you should always do things the 'right way.' Position and rotation at once without any exactness is the 'wrong way' to me. This will turn it around the hinge point / side of the door. (Stating the obvious:) I commented it so you could learn from it. If you ever make moving stuff CFrame is important.
Report Abuse
ggfunny1234 is not online. ggfunny1234
Joined: 09 Jul 2010
Total Posts: 3432
06 Jul 2012 11:20 PM
Thank you VERY much, Corecii!

The info was extremely helpful, I'll be sure to save all this in a file for future reference.

Although it was simply me testing CFrame and EulerAngles, I would still like to know how to do it, for whenever I might want to.

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