Hi, I want to use script to put a fish inside a net, (the net is just a cube), but I don’t know how. The fish is way smaller than the net, and I want to put several fish inside the net with a script. I know I can just do fish.Position = net.Position, but I don’t want all the fish to be in one location, instead I want them to be scattered around in random positions BUT still stay inside the net. How can I do this?
Ok so I solved this problem with this piece of code:
fish.Position = Vector3.new(net.Position.X+math.random(-0.5 * net.Size.X,0.5 * net.Size.X),net.Position.Y+math.random(-0.5 * net.Size.Y,0.5 * net.Size.Y),net.Position.Z+math.random(-0.5 * net.Size.Z,0.5 * net.Size.Z))
But now sometimes the fish sticks out from the edge. How do I make the fish stay inside the net?
If you want the positions randomized, just set the position to the net but add random values for X and Z that are within the size of the net. Assuming that your net has a flat surface, you can do:
fish.Position = net.Position + Vector3.new(math.random(-net.Size.X / 2, net.Size.X / 2), 0, math.random(-net.Size.Z / 2, net.Size.Z / 2))
Hope this helps.
Thanks for replying, but now I have another problem, which is sometimes the fish is at the very edge of the net, and parts of it stick out. How do I fix this?
Edit: I changed the 0.5 into 0.4 and it seems to work, but now the fishes are never touching the edges, I’m not sure if this will work in the long term
fish.Position = Vector3.new(net.Position.X+math.random(-0.5 * net.Size.X + 0.5 * fish.Size.X,0.5 * net.Size.X - 0.5 * fish.Size.X),net.Position.Y+math.random(-0.5 * net.Size.Y + 0.5 * fish.Size.Y,0.5 * net.Size.Y - 0.5 * fish.Size.Y),net.Position.Z+math.random(-0.5 * net.Size.Z + 0.5 * fish.Size.Z,0.5 * net.Size.Z - 0.5 * fish.Size.Z))
Basically just shorten the random range by half the size of your fish.
ty!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.