Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is this rotating the part when I'm changing the CFrame?

Asked by 5 years ago

So, I'm making a cannon and when the cannon is being shot it works perfectly fine but it rotates it 90 degrees when it's moving and it's annoying.

(I'm using TweenService by the way)

The bullet moves to the goal position I want it to, but it's rotating 90 degrees, the cannon's orientation is (0, 90, 0) but when I rotate the cannon to (0, 0, 0) it works perfectly fine with no rotations or anything but I need the cannon to face the direction I have it in which is (0, 90, 0) is there a way to keep the same rotation while moving the part?

local tweenService = game:GetService('TweenService')

local bullet = script.Parent.Bullet

local goals = {
    CFrame = CFrame.new(-2481.297, 266.085, -11116.204);
}

local info = TweenInfo.new(
    1,
    Enum.EasingStyle.Linear,
    Enum.EasingDirection.In
)

spawn(function()
    while wait(2.25) do
        local newBullet = bullet:Clone()
        newBullet.Transparency = 0
        newBullet.Touched:connect(function(hit)
            if hit.Parent:FindFirstChild('Humanoid') and hit.Parent ~= nil then
                hit.Parent:BreakJoints()
            elseif hit.Parent:IsA('Accessory') then
                hit.Parent.Parent:BreakJoints()
            end
        end)
        newBullet.Parent = script.Parent
        local down = tweenService:Create(newBullet, info, goals)
        down:Play()
        wait(.8)
        for i = 0, 1, .1 do
            newBullet.Transparency = newBullet.Transparency + 0.1
            wait()
        end
        newBullet:Destroy()
    end
end)

1 answer

Log in to vote
2
Answered by 5 years ago

CFrame describes both the position and rotation. This means that in order to keep the rotation the same, you need to adjust your CFrame to match the original rotation. You can try something like

targetCFrame + CFrame.new(Vector3.new(0,0,0), originalCFrame.lookVector)

Which will give you the target CFrame with the rotation adjusted to match the original rotation.

0
I'm not sure how to utilize that with TweenService though. YabaDabaD0O 505 — 5y
0
The lookVector isn't in degrees. It's a normalized vector which points in the direction of the rotation. User#6546 35 — 5y
Ad

Answer this question