Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --scripted by onlineone22
- --the tank should have equivalent y and z values. otherwise, it will average the values thereof and likely goof up.
- --the fish must be rotated such that the x axis is forward and backwards, and the z axis is side to side
- --the fish must be on the right side of the aquarium
- --The Explorer MUST look as such in order to work properly
- --Aquarium
- -- -Fish
- -- - -Swim
- -- -Tank
- -- - -Mesh
- --VARS/SETUP
- TweenService = game:GetService("TweenService");
- tiic = 100;--total increments in cycle (must be an integer above 1)
- pbei = 0.05;--pause between each increment
- sdmt = tiic * pbei;--start delay max time
- --100 * 0.05 = 5 seconds per cycle
- --for less lag, I would recommened reducing the total increments and pauses thereof
- --for inconsistency, I would change these for each fish slightly
- ttpc = 4;--tilt times per cycle
- maxRot = 30;--maximum rotation of the fish in degrees
- tweenTime = (tiic * pbei) / ttpc;
- fishRotateTween = TweenInfo.new(tweenTime, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 1, true, 0)
- fish = script.Parent;
- aqua = fish.Parent;--aquarium
- tank = aqua:WaitForChild("Tank");
- spacing = 15;--0 to 100 for the percent at which you want the fish to stay away from the middle and edge of the tank
- safe = 1 - ((math.random(spacing * 2)) / 100);--number by which to multiply the radius to find the safe space
- --circumference = pi * diameter
- diameter = safe * ((tank.Size.Y + tank.Size.Z) / 2);--(averages x and z)
- radius = diameter / 2;
- circ = math.pi * diameter;--circumference of the tank
- -------cri = 360 / tiic;--circumference rotation increment
- cmi = circ / tiic;--circumference movement increment
- --fish position is a random area in the allowed non-spaced area, starts in the middle of the tank, 0
- fish.Position = tank.Position + Vector3.new(radius, 0, 0);
- fish.Orientation = fish.Orientation + Vector3.new(maxRot * -1, 0, 0);
- --FUNCTIONS
- SwimInCircle = coroutine.wrap(function()
- while true do
- --rotate fish to face center piece from side, and up and down. alter rotation. (x = up and down, y = sideways, z = 0)
- --fish.CFrame = fish.CFrame * CFrame.Angles(0, math.rad(cri), 0)--rotation
- --increment fish moving in direction it's facing, staying within the cylindric cycle. alter x and z position.
- fish.CFrame = fish.CFrame + (fish.CFrame.lookVector * cmi);--forward
- wait(pbei);--pause between each recursive loop
- end
- end) print(tweenTime)
- --SOMETHING WRONG IN ROBLOX' TWEEN FUNCTION, NOT DOING IT CONSISTENTLY
- TweenFishTilt = coroutine.wrap(function()
- while true do print(Vector3.new(maxRot, fish.Orientation.Y + (360 / ttpc), 0))
- --reset maxRot in properties to account for negative flip, and updates the rotate value
- local fishRotateProperties = {Orientation = Vector3.new(maxRot, fish.Orientation.Y + (360 / ttpc), 0)};--FIX HERE
- --tweens the fish
- local Tween = TweenService:Create(fish, fishRotateTween, fishRotateProperties);
- Tween:Play();
- Tween.Completed:wait();--time between each tilt change, it should be (tiic * pbei) / ttpc but isn't
- maxRot = maxRot * -1;--switch the tween setting to set to negative
- end
- end)
- --BODY
- wait(math.random(sdmt) - 1);--time to wait after loading before procedure
- SwimInCircle();
- wait(tweenTime);
- TweenFishTilt();
Advertisement
Add Comment
Please, Sign In to add comment