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

How do you move a model using CFrame without adjusting the model's orientation?

Asked by 2 years ago

I cannot use

Model.PrimaryPart.Position

-because that doesn't bring welded parts with it. I also cannot use

Model:SetPrimaryPartCFrame

-because I need to move the model in a tween. (Unless that's possible- but I don't think so)

So I'm currently using:

--Position I'm moving the part to, (Works great)
local MouseHitRounded = CFrame.new(math.round(Mouse.Hit.Position.X/grid)*grid, math.round(Mouse.Hit.Position.Y/grid)*grid, math.round(Mouse.Hit.Position.Z/grid)*grid)

--Tween itself with CFrame.Angles, (Not so great)
local Tween = TS:Create(placingpart, TweenInfo.new(0.2, Enum.EasingStyle.Quart, Enum.EasingDirection.Out), {CFrame = CFrame.new(MouseHitRounded.X,MouseHitRounded.Y,MouseHitRounded.Z) * CFrame.Angles(0,0,0)})

Tween:Play()
Tween.Completed:Wait()

I've also tried

local Tween = TS:Create(placingpart, TweenInfo.new(0.2, Enum.EasingStyle.Quart, Enum.EasingDirection.Out), {CFrame = CFrame.new(MouseHitRounded.X,MouseHitRounded.Y,MouseHitRounded.Z) * CFrame.Angles(math.rad(placingpart.Orientation.X),
math.rad(placingpart.Orientation.Y),math.rad(placingpart.Orientation.Z)))})
--^^ (All on the same line, ScriptingHelpers was glitching so I had to split it up)

But that creates weird glitches where the part will bounce rotations back and forth.

Because I'm teleporting the part to the player's mouse, the code constantly runs- if that changes anything.

There are numerous threads with this same question that I've looked at, but the threads I've found haven't been under the same conditions. I've been stuck on this for a few days. Any help would be much appreciated. <3

0
"-because I need to move the model in a tween. (Unless that's possible- but I don't think so)" I believe you can actually! Couldn't you just write the table as {Position = Vector3.New(0,0,0)} or even {CFrame = CFrame.new()} wolftamer894 50 — 2y
0
The only issue is that when I just do "Position =" it's not accomodating for my welds that I need to teleport with the part. I just tried your CFrame.new() suggestion but even that seems to still be resetting the part's orientation to 0,0,0 barrettr500 53 — 2y

2 answers

Log in to vote
0
Answered by
NEILASc 84
2 years ago
CFrame.new(Vector3.new(0,0,0))

that only does position. not rotation.

0
Hmm I just tried that and it's resetting the part's orientation still. barrettr500 53 — 2y
0
couldnt you set the rotation after setting the position? NEILASc 84 — 2y
Ad
Log in to vote
0
Answered by
RAFA1608 543 Moderation Voter
2 years ago

i have come with a script a week ago that tweens models, see if this is any use

local ts = game:GetService("TweenService")
local rs = game:GetService("RunService")

function tween(obj, goal, es, ed, time) --uses ts:GetValue to "tween"
    if not obj.PrimaryPart then error("No primarypart, can't proceed") end
    local es = if es ~= nil then es else Enum.EasingStyle["Bounce"]
    local ed = if ed ~= nil then ed else Enum.EasingDirection["In"]

    local start = os.clock()
    local initial = obj.PrimaryPart.CFrame --initial position
    while true do
        rs.Heartbeat:Wait()
        local delta = math.clamp(
            (os.clock() - start)/time,
            0, 1) --gets delta (to use with ts:GetValue())
        if delta == 1 then
            print("finished")
            obj:SetPrimaryPartCFrame(goal)
            return
        end
        obj:SetPrimaryPartCFrame(initial:lerp(goal, ts:GetValue(delta, es, ed)))
    end
end

about the "keeping orientation" i think you could just use a constant orientation vector3

0
post scriptum: it does not work correctly if you use it on a model where the "tween" is already being processed RAFA1608 543 — 2y

Answer this question