so I’m trying to rotate a part.
This is the best result i could get.
local function updateCurrentPieceTransform()
TS:Create(piece, TweenInfo.new(0.5), {["CFrame"] = piece.CFrame * angle}):Play()
end
UIS.InputBegan:Connect(function(input, gpe)
if gpe then return end
if input.KeyCode == Enum.KeyCode.R then
local oldPresetOrientation = presetOrientation
presetOrientation += Vector3.FromAxis(presetDirection)*RotationScale.Value --> 1,0,0 * 10 --> 10,0,0
updateCurrentPieceTransform(CFrame.Angles(math.rad((presetOrientation.X + 180) % 360 - 180), math.rad((presetOrientation.Y + 180) % 360 - 180), math.rad((presetOrientation.Z + 180) % 360 - 180))) this is supposed to conver 360~0 to -180~180
print(math.rad((presetOrientation.X + 180) % 360 - 180), math.rad((presetOrientation.Y + 180) % 360 - 180), math.rad((presetOrientation.Z + 180) % 360 - 180))
elseif input.KeyCode == Enum.KeyCode.Z then
setOrientationDirection(Enum.Axis.X, "Z")
elseif input.KeyCode == Enum.KeyCode.X then
setOrientationDirection(Enum.Axis.Y, "X")
elseif input.KeyCode == Enum.KeyCode.C then
setOrientationDirection(Enum.Axis.Z, "C")
end
end)
I have 2 problems now though.
1 - This has a weird behaviour that only affects the first time you press R(the key to rotate)
2 - When its being tweened, i cannot move the part (and it’s supposed to follow the mouse). So until the tween finishes it won’t move.
Video:
1 Like
You won’t be able to tween the object’s cframe using the tween service if you also want to manipulate the cframe in other ways at the same time. If you have code that is updating the part’s cframe to follow the mouse, every time it does an update step, you could get the desired orientation from a separate system.
A hacky but easy way to do something like this would be to have a CFrameValue object that represents the orientation of the part. That can be the source of truth for the orientation, and you can use the TweenService to tween the Value. And in your follow function, you create a new cframe by doing Part.CFrame = CFrame.new(desiredPos) * OrientationTag.Value
1 Like
OK. I’ve solved the problem of the weird behaviour with the angles.
I replaced the += with = and did something like this
presetOrientation = Vector3.FromAxis(presetDirection)*RotationScale.Value
updateCurrentPieceTransform(CFrame.Angles(math.rad(presetOrientation.X),math.rad(presetOrientation.Y),math.rad(presetOrientation.Z)))
Well, this might sound weird but I’m changing the position/size in this script, and managing the position in another.
Also, could you give me an example of what are you actually suggesting to do?
TS:Create(CURRENT_PIECE.Value, TweenInfo.new(0.1), {Position = CalculatedHitPos}):Play()
is the current code in charge to update the position
I’d suggest either merging your scripts, or designating only one of them to actually have control over setting the cframe of the part. The hacky method that I mentioned earlier with a CFrameValue can work between scripts since the orientation script can set the CFrameValue, and the other script use the CFrameValue as the orientation component when it updates the part’s cframe.
Oh, I see what you mean. I’m going to try merging both, It’s just that im using RunService.Stepped to tween the position and i dont know at what point would that actually look any good. Give me some time.
I ended up using BodyPosition and BodyGyro. And they work flawlessly. Thanks for the advice anyway
1 Like