Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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.

2 comments

0

^Definitely the more effective option.

0

thank you!

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

This discussion is preserved as it was. New answers, comments, and votes are closed.