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

How to rotate something in 2 sides at the same time?

Asked by 9 years ago

I want to rotate not only Y axis but X too

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:

In this script, Y axis will rotate until it reaches 360 degrees, but I want to make the X axis turn 140 degrees at the same time

2 answers

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

This is actually a somewhat complicated problem. The obvious way is to use coroutines to make the two loops run at the same time, but that has the problem of getting them in sync.

The way I would solve this is to use a different style of loop:

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

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
Ad
Log in to vote
-1
Answered by 9 years ago

Easy, change you vector3 (0.2, 0.0, 0.0) to (0.2, 0.2, 0.0)

brick.Rotation = brick.Rotation + Vector3.new(0.2, 0.2, 0.0)
0
Please upvote! I am in negetives! yogipanda123 120 — 9y
0
The problem with this is that it will rotate *both* axii 360*, instead of just 140* on the X. adark 5487 — 9y

Answer this question