Hello!
I am trying to make a grappling hook like the one Rico Rodriguez has in the game Just Cause 4. Currently, I’m just trying to make a RopeConstraint that attaches to the character’s right forearm to the player’s mouse.hit. For some reason, it’s not doing anything. It’s not even giving me an error in the Output.
Here’s what I have so far:
local character = player.Character
local arm = character.RightLowerArm
local mouse = player:GetMouse()
mouse.Button2Up:Connect(function()
local rope = Instance.new("RopeConstraint")
local at0 = Instance.new("Attachment")
local at1 = Instance.new("Attachment")
rope.Parent = character
rope.Thickness = 0.05
rope.Attachment0 = at0
rope.Attachment1 = at1
rope.Length = 10
at0.Position = arm.Position
at1.Position = mouse.hit.p
print(mouse.hit.p)
end)
Well, the thing with this is it does look a like what I’m going for, but it doesn’t answer my question. I’m not very advanced in scripting, and don’t know where to look in the open-source place to find an example or whatever. I also don’t want to just blatantly copy something, I’m trying to make it myself.
Not sure if constraints are the best thing here but if you’re using them I’d suggest a rod constraint. Instead of creating a new one everytime, just change the one attachment each time. Set the rod length to the magnitude of attachment1.WorldPosition - attachment0.WorldPosition, and I guess you could try tweening its length to 0? Not sure how this would work with network ownership.
Sorry for the late response!
I had the same idea, and your RodConstraint idea is also something I will try out, but I still don’t know what’s making my script not work.
I think you’re using attachments wrong, the “position” value is local to the part they are inside, so if its 0,1,0, it will appear one stud above the origin of the part. What you would want to do is make a attachment inside the arm of the character, then put the second attachment inside the part that you hit and set its world position to the place where it hit.