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

Why isnt my move script working?

Asked by 9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

So whenever I run the script, the fish, (Who is the one moving) juts sinks to the bottom of the tank and stays there. Any help?

fish = script.Parent

while true do
for i=1,20 do
fish.CFrame = fish.CFrame + Vector3.new(0.1,0,0)
wait(0.1)
end
for i=1,31 do
fish.CFrame = fish.CFrame * CFrame.fromEulerAnglesXYZ(0,0.1,0)
wait(0.01)
end
for i=1,20 do
fish.CFrame = fish.CFrame - Vector3.new(0.1,0,0)
wait(0.1)
end
for i=1,31 do
fish.CFrame = fish.CFrame * CFrame.fromEulerAnglesXYZ(0,-0.1,0)
wait(0.01)
end
end

0
where does "i" get used? woodengop 1134 — 9y
0
Is the Fish anchored? BlueTaslem 18071 — 9y
0
If it were anchored it wouldn't fall to the bottom. yoshiegg6 176 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

I made this base upon our script, there are a lot of improvements to make but I did not have time to finish it.

You need to store the angle and apply it to the cframe so that it faces the direction you are traveling and you need to add a method to stop if going beneath the floor.

Hope this helps you.

fish = script.Parent
function curX()
    return fish.CFrame.x
end

function curY()
    return fish.CFrame.y
end

function curZ()
    return fish.CFrame.z
end

function ran(low, high) -- hole numbers only i think?
    return math.random(low, high)
end

while true do
    for i=1,ran(1, 100) do
        fish.CFrame = CFrame.new(curX() + 0.2, curY()+ 0.1, curZ()+ ran(10,100)/100)
        wait(0.1)
    end

    for i=1,ran(10,360) do 
        fish.CFrame = CFrame.new(curX(), curY(), curZ()) * CFrame.fromEulerAnglesXYZ(0,i/100,0) 
        wait(0.01) 
    end

    for i=1,ran(1, 100) do
        fish.CFrame = CFrame.new(curX() - 0.2, curY() -0.1, curZ() - ran(10,100)/100)
        wait(0.1)
    end

end

Ad

Answer this question