Hi. I am making a fishing quest for my game, so I made a fishing rod for testing so I could add it into my game, but it isn’t working as it should. Here’s the video:
And here’s the code:
local FishingRod = script.Parent;
local Hook = FishingRod:WaitForChild('Hook')
local debounce = false
local function on_Activated()
if not debounce then
debounce = true
local rope = Instance.new("RopeConstraint", Hook);
local Lure = Instance.new("Part", workspace);
Lure.Size = Vector3.new(.2, .2, .2)
Lure.CFrame = Hook.CFrame;
rope.Visible = true
rope.Length = (game.Players.LocalPlayer:GetMouse().Hit.p - Lure.CFrame.p).magnitude;
rope.Thickness = 0.1
rope.Restitution = 6
local attachment1 = Instance.new("Attachment")
local velo = Instance.new("BodyVelocity", Lure);
velo.MaxForce = Vector3.new(1,1,1) * math.huge
velo.P = 20
velo.Velocity = game.Players.LocalPlayer:GetMouse().Hit.lookVector * 50;
attachment1.Parent = Lure
rope.Attachment0 = Hook:FindFirstChild("Attachment")
local att0 = Hook:FindFirstChild("Attachment")
rope.Attachment1 = attachment1
attachment1.Position += Vector3.new(2.5,0, 0);
debounce = false
You have not specified what you really wanted it to do, I can only assume that you don’t want it to go directly to the mouse but to fall short.
The best thing for this would be to set a max distance for the rod. When using the rod you would want to fire it in the direction of the mouse. Using the same kind of script only set the position to be a fraction of the distance and then find the point of ground below. This way in order to throw the lure further they would have to aim further out and this would also mean that they could aim upwards to throw the lure.
I mean if you watch the video then the rope is going under the ground which I don’t want. Can you please help me with that?
That is because of the length, You would need to calculate the how much slack to give the rope. When you shorten the rope there will be less slack so it wont go into the ground.
When you set the length of a rope to be the magnitude it will be the furthest possible point, However the lure isn’t quite as far as that resulting in slack. It isnt a major issue, You will just need to take away a fraction of the ropes length. Play around with it until you are happy with the result and use that factor. This will take the distance into account so it will give better results.
How would I calculate the slack then?
It would be more effort than its worth, Id say play around with subtracting a percentage of the length until you get it how you want.
Alright, thanks, but I am weak in math… So I would still need a guide
Here’s how you can take away a percentage of the length
rope.Length = (game.Players.LocalPlayer:GetMouse().Hit.p - Lure.CFrame.p).magnitude * Persentage
So I can put my any percentage I want and play around with it until I get the right one?