Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Percentage magnitude of 2 vectors?

I'm trying to subtract 2 vectors and get the percentage of how close they are, this is what I got so far ( don't really like it because even if one of the bricks is way off it would give something like 89% instead of somewhere around 10%)

100 - ((brick1.Position / brick2.Position).magnitude * 100)

4 comments

0

Do you mean, you want to check how far a player is from their destination, the start point being where the quest/etc. was started?

0

Yeah something like that, except in this case, I have 2 bricks and I want to check how much does brick1 overlap brick2 in terms of percentage.

0

You mean overlap? I'm confused :p

0

Would this help? http://imgur.com/a/gIN18

1 answer

EDIT: Apparently this isn't what you wanted, but I'll keep it for future reference :P

First off, I believe you get magnitudes using subtraction, not division, so:

local mag = (pos1-pos2).Magnitude

Next, to use percentages, you need to have a value that state's what 100% would be, so:

local distanceToTravel = (pos1-pos2).Magnitude

Then, to calculate the percentage, you get the maximum percentage (100%), divide it by the "100% value", then times it by the current value:

-- I also added in a few other things :)
local distanceToTravel = (start-destination).Magnitude
local travelledDistance = false

while travelledDistance == false do -- looping to update
	local percentage = 100/distanceToTravel*((curPos-destination).Magnitude)
	if percentage >= 100 then -- checks to see if percentage is 100
		travelledDistance = true -- disables loop
	end
end

Hope I helped! If you have any questions, please ask!

~TDP

This discussion is preserved as it was. New answers, comments, and votes are closed.