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

[SOLVED] Detecting if a number is within x of another number?

I'm not asking for a script, but just guidance.

I'm working on a tree generator, and I'm doing well. I just finished branch generation, but I have issues with branches crowding a single side, leaving the other sides bare. Could anyone point me in the right direction to how to achieve this?

I have attempted to use a table to store previous angles of branches and loop through, but my brain hurts trying to figure out the logic needed behind the calculations for detecting if the angle randomly chosen is too close to another angle.

4 comments

0

You can make the X and Z if you use both, and change them so their values are negative. Which will make the values opposite and reflect so its on each side.

0

I have multiple branches.. I'm trying to detect if values are within a range of e.g 10 numbers of the one just randomly chosen.

0

You could use the Dot Product to calculate the angle between branches (http://robloxdev.com/articles/Calculating-Dot-Products)

0

You can use if statements to check if the branches are <= (less than or equal to). If thats what you mean.

1 answer

Found a solution, on a page about C#.

if x > y - z and x < y + z then
 -- do stuff
end

X is the number you want to check; Y is a number that is being checked against Z is how far X has to be from Y

1 comment

0

Glad you found a solution, hope it all works out

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