matamouros [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=15203 Maths for deflecting two objects off each other <p>Hi all, just a quick noob question. I'm struggling with making two objects (asteroids in this case) coming down a trajectory on x,y and colliding, deflect each other a little more realistically (but without having to implement a physics engine!). I don't have the maths skills as of yet, I'm guessing something to do with angles/trigonometry?</p> <p>At the moment I'm basically forcing the leftmost asteroid to the left and the rightmost object to the right, but 90% of times this just looks very unnatural.</p> <p>Would someone kindly point me some resource I could check up on/read/watch on how to approach this? I don't have the smarts to figure it out on my own, but will be more than ok researching it on my own - just need to be pointed in the right direction. Any tips or pointers would be greatly appreciated.</p> <p>Thank you in advance!</p> <p>Pedro.</p> https://www.lexaloffle.com/bbs/?tid=48560 https://www.lexaloffle.com/bbs/?tid=48560 Tue, 19 Jul 2022 17:08:54 UTC Random bool <p>Aw man, I'm so sorry, I feel really silly... How on earth do you generate a random bool? I can't find any way to cast an int into a bool, so I'm down to doing the sort of stuff below:</p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>randbool=flr(rnd(2)) if randbool==0 then randbool=false else randbool=true end</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>This feels really dirty and silly. What's the established way of doing this please? And apologies in advance.</p> <p>Thanks,</p> <p>Pedro.</p> https://www.lexaloffle.com/bbs/?tid=48319 https://www.lexaloffle.com/bbs/?tid=48319 Sun, 26 Jun 2022 18:03:01 UTC Weird thing, can't catch zero anymore <p>Hi everyone, I think this can't be a bug that only I just found out so I'm posting it here for some help instead of in the bugs forum.</p> <p>I seem to be having the weirdest behaviour easing out a negative var towards 0: it never becomes zero again (either negative or positive), despite printing as such. Check the below reproducer code and gif, neither y==0 nor y==-0 conditions catch the zero, even though at first you can see <code>true</code>.</p> <p>Please help?</p> <p>Thanks!</p> <img style="margin-bottom:16px" border=0 src="/media/15203/untitled_2.gif" alt="" /> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>function _init() y=0 end function _update() y*=0.85 if btn(2) then y-=0.65 end end function _draw() cls() print(&quot;time: &quot;..time()) print(&quot;y=&quot;..y) print(&quot;is y==0? &quot;..(y==0 and 'true' or 'false')) print(&quot;is y==-0? &quot;..(y==-0 and 'true' or 'false')) end</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> https://www.lexaloffle.com/bbs/?tid=48218 https://www.lexaloffle.com/bbs/?tid=48218 Sun, 19 Jun 2022 11:45:16 UTC