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

How do i make a part move at a specific position upward at a constant rate?

Asked by
rexpex 45
7 years ago
aura = Instance.new("Part", game.Workspace)

for i=5, 10 do
wait(0.5)
    aura.CFrame = aura.CFrame + CFrame.new(i,i,i)
end


4 answers

Log in to vote
0
Answered by 7 years ago

You can't add CFrames together or set the value like that. You can do

aura = Instance.new("Part", game.Workspace)
for i=1, 10 do
wait(0.5)
aura.CFrame = aura.CFrame + Vector3.new(0,5,0)-- Edit the middle value to how much you want it to move up.
end
Ad
Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

Your Problem

  • On line 5 you are adding i onto every axis. In order to move "up" - you must add to the Y-axis.

  • Also, CFrames should be multiplied. Not added.

"constant rate" --> To make the part move at a constant rate, you have to replace "i" with a number, since "i" changes with each iteration. Using "i" is more like a compound rate.


Code

local aura = Instance.new("Part", workspace)
local rate = 1;

for i = 5, 10 do
    wait(0.5)
    aura.CFrame = aura.CFrame * CFrame.new(0,rate,0)
end

I suggest making this a while loop, or editing the for loop's bounds, seeing as it will currently only iterate 5 times.

Log in to vote
0
Answered by 7 years ago

First, you have to understand: What are the coordinates I am using?

There are X, Y, and Z coordinates that determine the position of an instance on a grid. The Z coordinate will not be important right now in your situation.

The X coordinate determines where the instance is horizontally.

The Y coordinate determines where the instance is vertically.

Using this, we can now fix up a script to match your situation.

aura = Instance.new("Part", game.Workspace)
for i = 5, 10 do
    wait(0.5)
aura.CFrame = aura.CFrame + Vector3.new(0, 1, 0)
end

This raises the CFrame of the part by one Y coordinate every 0.5 seconds. It will always raise by one, being a constant rate.

Hope this helped! Please accept this answer!

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

The previous answers posted are all correct! I just want to give a little bonus answer towards how to move a model, no matter what rotation it is at. The model must have a PrimaryPart.

local model = game.Workspace.Model
local prime = model.PrimaryPart
local function moveModel()
    for i = 1, 200 do
        model:SetPrimaryPartCFrame(prime.CFrame * CFrame.new(0, 1, 0))
        wait()
    end
end
moveModel()

Basically, the SetPrimaryPartCFrame takes the Primary Part of the model and CFrames it at a constant rate of 1 stud per wait(). This can be applied to other parts too, as mentioned from previous answers. :)

Answer this question