How would I calculate this?

Hello everyone!

I’m making a rope grapple for my group;

And I need the length of the rope to be enough based on where the player is standing, to where they click. However, I’m lacking the idea of how I would go about scripting that. Any ideas?

Thanks in advanced!

What do you mean by “enough” ?

You can get the straight distance between two points using
(posA - posB).magnitude
And you could roughly add some leeway by adding a bit, like 5.

Well, say I click from 50 studs away. I want the length of the rope to be perfectly straight. Same if I were to say click from 30 studs away.

Yeah, just subtract the two positions of the ends of the ropes, then use .magnitude to get the length of that vector.
local ropeLength = (attachment1.WorldPosition-attachment2.WorldPosition).magnitude

Thanks a ton! I’ve never used Magnitude before. I’ll look into it, seems to give me a good read.
image

1 Like