Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Percentage magnitude of 2 vectors?

Asked by
Omarstein 100
7 years ago

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)
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? TheDeadlyPanther 2460 — 7y
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. Omarstein 100 — 7y
0
You mean overlap? I'm confused :p TheDeadlyPanther 2460 — 7y
0
Would this help? http://imgur.com/a/gIN18 Omarstein 100 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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

Ad

Answer this question