Page 4 of 4

### Re: [Tutorials] Making a simple 2D physics engine

Posted: Thu Nov 27, 2014 9:15 am
Thanks! Best tutorials about 2D physics!)

### Re: [Tutorials] Making a simple 2D physics engine

Posted: Fri Dec 12, 2014 12:06 pm
Snuux wrote:Thanks! Best tutorials about 2D physics!)
Thank you very much, I really appreciate it

Also, the reason why it took me forever to answer this is because I was waiting to have the third tutorial, in order to have more content in the same post. Naturally, as a huge procrastinator that I am, it took several hundreds of years, but it's finally here! Half-Life 3 confirmed!

I'm not posting a link here because I want you guys to check out the main post. There are some new information I want you guys to know about, so go check that out! Also, MANY, MANY THANKS for your support and feedback! In less than a month the Physics Tutorial post was the most visited post of my blog, and with your guys' boost, my blog has almost 10.000 views! So, from the depths of my heart, THANK YOU!

### Re: [Tutorials] Making a simple 2D physics engine

Posted: Fri Dec 12, 2014 12:50 pm
Great work on the tutorials, I can see that you put in a lot of effort there.

Just have a small suggestion regarding the following piece of code:

Code: Select all

``````obj1.speedx = math.min( math.max(obj1.speedx, -maxspeed), maxspeed)
obj1.speedy = math.min( math.max(obj1.speedy, -maxspeed), maxspeed)``````
It clamps each axis separately which means that diagonally moving objects can move faster.

here is an alternative approach:

Code: Select all

``````  local d = math.sqrt(obj1.speedx*obj1.speedx + obj1.speedy*obj1.speedy)
if d > maxspeed then
local n = 1/d * maxspeed
obj1.speedx, obj1.speedy = obj1.speedx * n, obj1.speedy * n
end``````
Again, sorry to nitpick, love the tutorials!

### Re: [Tutorials] Making a simple 2D physics engine

Posted: Fri Dec 12, 2014 4:23 pm
I usually do that way because in most games I don't mind about diagonal speed, but your approach is really nice and clever, thanks for sharing! I'll make sure to include it in the corresponding part of the tutorial and give credits for you.
Also, it's not nitpicking, as I said in the main post any suggestions are welcome, and having multiple methods for more things is always nice, so thank you very much