I know that collision detection is a bit of a FAQ, but I have a specific question.
I have implemented circle-on-square collision detection in a very basic manner. Basically it checks the radius of the circle against the center of the square and then also does a short calculation for the corners.
However, because of the resolution of the check it seems to always encounter corner collisions. The speed ends up being too great for the refresh rate and the circle overlaps the square and triggers a collision on the corner.
So I'm thinking that my physics calculations need a paradigm shit. I should probably stop relying on the framerate to set the speed of animated objects.
I am thinking about moving to a time-elapsed based approach. I can then render based on where the objects should be at a point in time rather than simply updating them based on their acceleration and velocity per frame.
Either that or I will start performing look-ahead calculations to make sure that the next velocity step won't land my object inside of another one. Then doing some kind of calculation to determine where it should end up at the next step. This doesn't seem very good, I'm afraid of causing a jump in animation.
Anyway, I was wondering if anyone had any suggestions. I'm sure that some of you have encountered this sort of a problem and had to work out a solution.
I'm writing a very simple sketch that moves a square around based on keyboard input.
Keyboard directions just add some acceleration in their direction up to a certain speed cap (the acceleration in each direction can only be increased once each draw loop). There is also a constant drag acceleration which will slow the square when input stops.
The problem that I'm having is that the square will appear to jump in the animation at higher speeds.
I know why this is: the square gets moved at its speed each time the draw loop executes. So at higher speeds it will jump around because its speed starts moving it a noticeable distance from its start location per draw loop.
I tried a couple things - I brought up the frame rate, which I thought might allow for a finer grained rendering of the movement, but that didn't fix the issue. I also started rendering offscreen (via PGraphics) and only drawing to the canvas once per draw loop. That also didn't fix the issue.
My question is what is there a technique that I can use to smooth out the animation so that it doesn't appear to jump but still moves at the same speed? I want to fill in the animation from its start point to where it will end up at the end of the draw iteration.
Or maybe just point out the flaw in my movement algorithm. This is my first foray into animation so I'm pretty green.