My fish keeps drowning when it reaches the center of water.
#1
It correctly moves the fish back to water when it isn't in water (and there's water in the world for it to swim to), but whenever it reaches near the X-center of the water,
fish Wrote:1
FISH IS DYING GARGGGLEPTDDD
1
FISH IS DYING GARGGGLEPTDDD
1
FISH IS DYING GARGGGLEPTDDD

(1 is the number of Water blocks in the world.)

The function that drives me nuts is iNeedTheWater:

[lua]
local scented = false

function find()
local players = game.Players:getChildren()
local closest = nil
local distance = 25 --Feel free to change this value; it's how far away they can "smell" players
for q = 1, #players do
if players[q].Character and players[q].Character:getChild("Body") then
if players[q].Character.Body.PositionConfusedub(script.Parent.Position).length < distance then
closest = players[q].Character.Body
distance = players[q].Character.Body.PositionConfusedub(script.Parent.Position).length
end end end
if iNeedTheWater() == false then
if closest then
swim(closest.Position)
scented = true
else
swim(Vec2D(math.random(script.Parent.Position.x - 5.01), math.random(script.Parent.Position.x + 5.01)))
scented = false
end
else
swim(findTheWater().Position)
end
end

function swim(target)
local ecks = 0
local why = 0
local vel = script.Parent:getChild("VelocityController")
if target.x > script.Parent.Position.x then
ecks = 3
script.Parent:getChild("FISHEEE").FlipX = true
else
ecks = -3
script.Parent:getChild("FISHEEE").FlipX = false
end
if target.y > script.Parent.Position.y then
why = 1.5
else
why = -2
end
vel.Velocity = Vec2D(ecks, why)
end

function checkForWater(parental, tabull)
local items = parental:getChildren()
for q = 1, #items do
if items[q]:isA("Water") then
table.insert(tabull, items[q])
else
tabull = checkForWater(items[q], tabull)
end
end
return tabull
end

function findTheWater()
local waterz = checkForWater(game.World, {})
if #waterz > 0 then
print(#waterz)
local closewater = nil
local nearest = 1000
for e = 1, #waterz do
if waterz[e].PositionConfusedub(script.Parent.Position).length < nearest then
closewater = waterz[e]
nearest = waterz[e].PositionConfusedub(script.Parent.Position).length
end end
if closewater then
return closewater
end
end
end

function iNeedTheWater()
local watery = findTheWater()
local dying = false
if watery then
if script.Parent.Position.x > watery.Position.x and script.Parent.Position.x - watery.Position.x >= 5 then
if script.Parent.Position.x - (watery.Size.x * 0.5) > watery.Position.x then
dying = true
end
elseif script.Parent.Position.x < watery.Position.x and watery.Position.x - script.Parent.Position.x >= 5 then
if watery.Position.x - (watery.Size.x * 0.5) < script.Parent.Position.x then
dying = true
end
end
if script.Parent.Position.y > watery.Position.y and script.Parent.Position.y - watery.Position.y >= 5 then
if script.Parent.Position.y - (watery.Size.y * 0.5) > watery.Position.y then
dying = true
end
elseif script.Parent.Position.y < watery.Position.y and watery.Position.y - script.Parent.Position.y >= 5 then
if watery.Position.y - (watery.Size.y * 0.5) < script.Parent.Position.y then
dying = true
end
end
if dying == true then
print("FISH IS DYING GLARGLEPTHDDD")
return true
else
return false
end
end
end




while true do
if scented then
sleep(0.05)
else
sleep(0.5)
end
find()
if script.Parent:getChild("FISHEEE").Image == "http://i41.tinypic.com/35crcbs.png" then
script.Parent:getChild("FISHEEE").Image = "http://i42.tinypic.com/25qg9yb.png"
else
script.Parent:getChild("FISHEEE").Image = "http://i41.tinypic.com/35crcbs.png"
end
end
[/lua]
Reply


Messages In This Thread
My fish keeps drowning when it reaches the center of water. - by Qwertygiy - 12-26-2011, 01:25 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)