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

How do I make this sinking ship go forwards a little slower?

Asked by 6 years ago
Edited 6 years ago

Hiya! I'm attempting to script a sinking ship simulator game using this script:

local OceanLiner = script.Parent

for i = 1,1,0 do
    OceanLiner:SetPrimaryPartCFrame(OceanLiner:GetPrimaryPartCFrame() * CFrame.new(-i,-i,0) * CFrame.Angles(0,0,math.rad(0.5)))
    wait (0.1)
end

And as you can see, I'm making it go down while going forwards, and I want it to go forwards a little slower than it goes down, but if I change it from for i = 1,1,0 do to for i = 0.9,1,0 do, the model doesn't move at all. What am I doing wrong?

2 answers

Log in to vote
1
Answered by 6 years ago

In this case I think it would be better to use the lerp function in CFrame then you can control the intivals in more detail. More information about lerp can be found here.

Example:-

local curCF = script.Parent:GetPrimaryPartCFrame()
local endCF = curCF * CFrame.new([end position]) * CFrame.Angles(0,0,math.rad(0.5)))

for i=0, 1, 0.1 do -- change inc amount if needed
    curCF:SetPrimaryPartCFrame(curCF:lerp(endCF, i)) -- i is the % from to the goal range 0~1
    wait() -- change if needed
end 

I hope this helps.

0
^Definitely the more effective option. Axceed_Xlr 380 — 6y
0
thank you! User#21980 0 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

If you want it to go slower, because of how the for loop works, you'll have to change both the first and second parameter (0.9, 0.9, 0) rather than only the first one (0.9, 1, 0). To keep it simple, in the following script all I did was copy yours and add a new variable "a". Just change it to whatever number you wish and it will set it as both the first and second parameter to your loop: the smaller the number you choose, the slower your ship will sink.

local OceanLiner = script.Parent
local a = 0.9

for i = a,a,0 do
    OceanLiner:SetPrimaryPartCFrame(OceanLiner:GetPrimaryPartCFrame() * CFrame.new(-i,-i,0) * CFrame.Angles(0,0,math.rad(0.5)))
    wait (0.1)
end

Answer this question