tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
|
| 13 Jul 2014 09:15 PM |
I'm making a brick rotate on the Z axis 45 degrees every time a specific thing happens. It rotates correctly the first few times, but eventually it will to backwards 45 degrees, then go forwards 45 degrees and ext. This causes it to just shake back and fourth. I'm not really sure what's up here, but this is a snipped of the code:
part.CFrame = CFrame.new(part.Position.X,part.Position.Y,part.Position.Z) * CFrame.Angles(math.rad(part.Rotation.X),math.rad(part.Rotation.Y),math.rad(part.Rotation.Z+45))
Thanks! |
|
|
| Report Abuse |
|
|
tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
| |
|
tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
| |
|
tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
| |
|
LuaSlayer
|
  |
| Joined: 09 Jul 2014 |
| Total Posts: 38 |
|
|
| 13 Jul 2014 10:15 PM |
part.CFrame = CFrame.new(part.Position.X,part.Position.Y,part.Position.Z) * CFrame.Angles(math.rad(part.Rotation.X),math.rad(part.Rotation.Y),math.rad(part.Rotation.Z) + Vector3.new(0, 0, 45)
or
part.CFrame = CFrame.new(part.Position.X,part.Position.Y,part.Position.Z) * CFrame.Angles(math.rad(part.Rotation.X),math.rad(part.Rotation.Y),math.rad(part.Rotation.Z) + CFrame.new(0, 0, 45)
or
part.CFrame = CFrame.new(part.Position.X,part.Position.Y,part.Position.Z) * CFrame.Angles(math.rad(part.Rotation.X),math.rad(part.Rotation.Y),math.rad(part.Rotation.Z) + CFrame.Angles(0, 0, 45) |
|
|
| Report Abuse |
|
|
tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
|
| 13 Jul 2014 10:41 PM |
| I tried all three, and neither of them fixed the problem... It still won't make a full rotation. |
|
|
| Report Abuse |
|
|
tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
|
| 13 Jul 2014 10:42 PM |
| WAIT, I put it on the wrong line... Lemme retest. |
|
|
| Report Abuse |
|
|
tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
|
| 13 Jul 2014 10:45 PM |
I tried them, and the first one does nothing while the other two throw an error.
I should make a note that I posted the wrong code to an extent... The one that's broken is this:
part.CFrame = CFrame.new(part.Position.X,part.Position.Y,part.Position.Z) * CFrame.Angles(math.rad(part.Rotation.X),math.rad(part.Rotation.Y+45),math.rad(part.Rotation.Z))
The Y is edited instead of the Z |
|
|
| Report Abuse |
|
|
|
| 13 Jul 2014 10:57 PM |
| part.CFrame = part.CFrame*CFrame.Angles(0, 0, math.pi/4) |
|
|
| Report Abuse |
|
|
tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
|
| 13 Jul 2014 11:11 PM |
^
I tried replacing +45 with +math.pi/4 but that didn't fix the problem... It also made it move by 1 degree instead of 45. :\ |
|
|
| Report Abuse |
|
|
tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
| |
|
tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
| |
|
|
| 14 Jul 2014 12:44 AM |
| code works fine(rotating part 45degrees on z axis). its probably something else inside of your script |
|
|
| Report Abuse |
|
|
tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
|
| 14 Jul 2014 11:39 AM |
it rotates fine the first few times, but eventually it sorta just gets stuck on itself (Rotating back and fourth). This is all for a Gui based move tool. I'll post the script below:
mouse = game.Players.LocalPlayer:GetMouse()
mouse.KeyDown:connect(function (key) if script.ClonedBrick.Value ~= nil then
if key == "s" then game.Soundscape.Click:play() if script.Parent.Clicked.DragType.Value < 1 then script.Parent.Clicked.DragType.Value = script.Parent.Clicked.DragType.Value+1 else script.Parent.Clicked.DragType.Value = 0 end end if key == "t" then game.Soundscape.Click:play() script.ClonedBrick.Value.CFrame = CFrame.new(script.ClonedBrick.Value.Position.X,script.ClonedBrick.Value.Position.Y,script.ClonedBrick.Value.Position.Z) * CFrame.Angles(math.rad(script.ClonedBrick.Value.Rotation.X),math.rad(script.ClonedBrick.Value.Rotation.Y),math.rad(script.ClonedBrick.Value.Rotation.Z+45)) end if key == "r" then game.Soundscape.Click:play() script.ClonedBrick.Value.CFrame = CFrame.new(script.ClonedBrick.Value.Position.X,script.ClonedBrick.Value.Position.Y,script.ClonedBrick.Value.Position.Z) * CFrame.Angles(math.rad(script.ClonedBrick.Value.Rotation.X),math.rad(script.ClonedBrick.Value.Rotation.Y+45),math.rad(script.ClonedBrick.Value.Rotation.Z)) end if key == "g" then game.Soundscape.Click:play() if script.Parent.Clicked.Grid.Value == 0 then script.Parent.Clicked.Grid.Value = 1 else script.Parent.Clicked.Grid.Value = 0 end end end end)
|
|
|
| Report Abuse |
|
|
tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
|
| 14 Jul 2014 11:40 AM |
| Oh, and I established that I'm rotating on the Y axis. The original post was a mistake. |
|
|
| Report Abuse |
|
|
tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
| |
|
tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
| |
|
tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
| |
|
tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
| |
|
tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
| |
|
|
| 14 Jul 2014 03:14 PM |
Whenever you need to rotate something you only need to do this:
local sx, sy, sz, m00, m01, m02, m10, m11, m12, m20, m21, m22 = Part.CFrame:components() local X = math.atan2(-m12, m22) local Y = math.asin(m02) local Z = math.atan2(-m01, m00) Part.CFrame = CFrame.new(Part.CFrame.p)*CFrame.Angles(X,Y,Z)
Then add however much you want to rotate the brick to the X,Y,Z components. Example:
Part.CFrame = CFrame.new(Part.CFrame.p)*CFrame.Angles(X+math.pi/2,Y,Z)
|
|
|
| Report Abuse |
|
|
|
| 14 Jul 2014 03:18 PM |
Or if you want even simpler rotation:
X = 0 Y = 0 Z = math.pi/2
Part.CFrame = Part.CFrame*CFrame.Angles(X,Y,Z)
X, Y, and Z being how much you want to rotate the part. |
|
|
| Report Abuse |
|
|
|
| 14 Jul 2014 05:45 PM |
"local sx, sy, sz, m00, m01, m02, m10, m11, m12, m20, m21, m22 = Part.CFrame:components() local X = math.atan2(-m12, m22) local Y = math.asin(m02) local Z = math.atan2(-m01, m00) Part.CFrame = CFrame.new(Part.CFrame.p)*CFrame.Angles(X,Y,Z)
Then add however much you want to rotate the brick to the X,Y,Z components. Example:
Part.CFrame = CFrame.new(Part.CFrame.p)*CFrame.Angles(X+math.pi/2,Y,Z) "
O_o
@OP this should work. sorry i wouldnt usually just rewrite the script but im feeling lazy and figured this would be easier...
mouse = game.Players.LocalPlayer:GetMouse()
mouse.KeyDown:connect(function (key) local brick = script.ClonedBrick.Value if brick then
game.Soundscape.Click:play() local x, y, z = 0 if key == "s" then local dragtype = script.Parent.Clicked.DragType dragtype.Value = dragtype.Value < 1 and (dragType.Value + 1) or 0 elseif key == "g" then local grid = script.Parent.Clicked.Grid grid.Value = grid.Value == 0 and 1 or 0 elseif key == "t" then z = math.pi/4 elseif key == "r" then y = math.pi/4 end brick.CFrame = brick.CFrame * CFrame.Angles(x, y, z) end) |
|
|
| Report Abuse |
|
|
tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
|
| 14 Jul 2014 06:41 PM |
^
That shows several errors. Every time I fix one of them, another pops up .3.
I'll just incorporate some of that code into mine. |
|
|
| Report Abuse |
|
|
tinarg
|
  |
| Joined: 18 Jun 2010 |
| Total Posts: 4925 |
|
|
| 14 Jul 2014 07:03 PM |
| When I incorporated it, it didn't work... EAUGH, WHY IS THIS SO HARD!? THIS SHOULD BE SIMPLE! |
|
|
| Report Abuse |
|
|