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

Rotation script not working, how do I fix it?

Asked by 9 years ago

Some time ago I asked about how to rotate 2 sides at the same time, it worked when I used it in just ONE block

brick = Instance.new("Part", game.Workspace)
brick.Name = "Hello"
brick.Size = Vector3.new(4,4,6)
brick.Position = Vector3.new(1, 28.9, 1)
brick.Anchored = true
for Num = 1, 360/0.2 do
brick.Rotation = brick.Rotation + Vector3.new(0.2, 0.0, 0)
wait(0.05)
end --[ This is a *For* loop, for loops can be used in many ways, as they stop once "Num" reaches the second number (which I have put as division (360/0.2), once Num reaches the limit specified, the loop will stop and your brick should have rotated one full 360 degree turn. ]
--With that in mind, if you want the brick to rotate infinitely, just do:

It worked for me when I used it in one block but now I did this

brick = game.Workspace.Missile
brick.Name = "Missile 2"

local startTime = tick()
local elapsedTime = 0
local rotTime = 90 -- in seconds
-- This is equivalent to (360/.02)*.05

local desiredRot = Vector3.new(140, 360, 0) -- This is how much the block will rotate about each axis over the 'rotTime'

while elapsedTime < rotTime do
    elapsedTime = tick() - startTime
    if elapsedTime > rotTime then
        elapsedTime = rotTime -- so that it doesn't go over.
    end

    brick.Rotation = desiredRot*(elapsedTime/rotTime)
    wait()
end

(Missile is a model not a single part) And it stopped working, it doesn't work because is a model or what?

1 answer

Log in to vote
1
Answered by 9 years ago

You can rotate a part using CFrame. You can also change a models CFrame! To do this in the command bar you need to add the model's primarypart.

brick = game.Workspace.Missile --Is missile a model?

local startTime = tick()
local elapsedTime = 0
local rotTime = 90 -- in seconds
-- This is equivalent to (360/.02)*.05

local desiredRot = CFrame.Angles(math.rad(140), math.rad(360), 0) -- This is how much the block will rotate about each axis over the 'rotTime'

while elapsedTime < rotTime do
    elapsedTime = tick() - startTime
    if elapsedTime > rotTime then
        elapsedTime = rotTime -- so that it doesn't go over.
    end

    brick:SetPrimaryPartCFrame(brick.CFrame * desiredRot*(elapsedTime/rotTime))
    wait()
end

while elapsedTime > rotTime do
        elapsedTime = rotTime
end

Hope it helps! Tell me if it doesn't work.

Ad

Answer this question