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

Object isn't rotating when I'm trying to move it?

Asked by
Troidit 253 Moderation Voter
7 years ago
Edited 7 years ago

I've made a door that moves up and down, but the door itself turns 90 degrees when it starts moving. So I tried to add a way to keep the object at the same rotation as it moves down and up but I'm not doing something right?

door = script.Parent.Door
debounce = false
open = true --Door open or not open


script.Parent.DoorToggle.Event:connect(function() --This is a bindable function which is fired from another script
    if not debounce then
        debounce = true
        if open then
            for i=10,180 do
                door.CFrame = CFrame.new(door.Position + Vector3.new(0,-0.1,0))
                door.Rotation = CFrame.Angles(0,90,0) --Something is wrong here
                wait()
            end
            open = false
        elseif not open then
            for i=10,180 do
                door.CFrame = CFrame.new(door.Position + Vector3.new(0,0.1,0))
                door.Rotation = CFrame.Angles(0,90,0) --Something is wrong here too
                wait()
            end
            open = true
        end
        debounce = false
    end
end)

I've only recently started learning CFraming.

1 answer

Log in to vote
1
Answered by
Link150 1355 Badge of Merit Moderation Voter
7 years ago
Edited 7 years ago

You can't set an object's Rotation property to a CFrame, the Rotation property is of type Vector3.

What you want to do is combine two CFrames together using the multiplication * operator and assign it to your door's CFrame property.

-- Don't forget, CFrames expect the angles to be given in radians, not degrees!
door.CFrame = door.CFrame * CFrame.Angles(0, math.rad(90), 0)

All you need to remember is that you add vectors, but you multiply CFrames.

See BlueTaslem's answer here, for more details about vectors and CFrames.

0
Thanks! Troidit 253 — 7y
Ad

Answer this question