Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Pythagoras Macro

Not actually a question but a solution I haven't found on here yet so I am gonna share it. I have ran across the problem to quickly calculate the distance of a character to another flying or elevated character in several sessions now. This macro solves the problem by calculating the hypotenuse: The Distance to the target is [[ceil((?{Height of target in feet?|}**2+?{Distance to you in feet?|}**2)**0.5)]] feet.
1685039327
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Hi Grobag! It's come up before, but a very good place for this to live would be the  Tips n Tricks  thread. If you post there, I'll add it to the index next time I do an edit.
<a href="https://app.roll20.net/forum/post/10723963/pythagorean-macro/?pageforid=10724111#post-10724111" rel="nofollow">https://app.roll20.net/forum/post/10723963/pythagorean-macro/?pageforid=10724111#post-10724111</a> You can use this directly in chat: [[ [[ [[?{A}**2]] + [[?{B}**2]] ]]**0.5 ]] Or if you want to get fancy (I borrowed the decimal portion from GiGs - thanks!): $[[0.computed]]&amp;sup2; + $[[2.computed]]&amp;sup2; = [[ round([[ [[[[?{A}]]**2]] + [[[[?{B}]]**2]] ]]**0.5*10)/10 ]]&amp;sup2;
1685077971

Edited 1685078324
GiGs
Pro
Sheet Author
API Scripter
Thank you for that mention, Jarren. Your code looks good, but there are too many inline roll brackets to my liking. They can cause lag and make the macro less readable. I would do it like this: $[[0.computed]]&amp;sup2; + $[[1.computed]]&amp;sup2; = [[ round( ([[?{A}]]**2 + [[?{B}]]**2)**0.5 * 10)/10 ]]&amp;sup2; Roll20 will do a lot of calculation without inline roll brackets, and you can use normal parenthesis the way you can in normal arithmetic a lot of the time. Likewise that original chat macro could be [[ ( ?{A}**2 + ?{B}**2 )**0.5 ]]
keithcurtis said: Hi Grobag! It's come up before, but a very good place for this to live would be the&nbsp; Tips n Tricks &nbsp;thread. If you post there, I'll add it to the index next time I do an edit. Thanks, I'll post my macro there!