|
| 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 |
|
|
|
| 06 Jul 2012 10:25 PM |
| You need to not only CFrame the doors rotation, but also CFrame the doors position. |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|