I am trying to write the code for a boomerang the character can use as a weapon, and it is giving me far more trouble than I thought it would
First of all, I'm only working in 2D, and it is a side view, so Y is up.
I'm not trying to create a wide arching path; for the most part I just want the boomerang to go out, hit a target point, and come straight back to the player.
This should be easy.
But there are problems with getting these minute details right. First of all, the boomerang shouldn't be moving at top speed the whole time; it needs to slow down gradually and then speed up as it returns. I would like (and its easy) to have a max speed, so for the most part it will be moving at its optimal speed, but when I get to that first return point there needs to be (even if its not really noticeable) slow down and speed up. Without this it looks cheap and unnatural.
So my first plan was to simply have the boomerang, each frame, calculate the direction to reach its target, and add a little bit of velocity in that direction. However, this created problems where the boomerang could easily just loop around its target because it can't nudge the velocity enough. But when I push that nudge value up too high, the path looks stiff because there is not enough gradual motion to it.
By the way, its target is first a set point in front of the player, and once it reaches that, the target becomes the player itself.
I was studying some old retro games, and I noticed their patterns suggest they move each axis individually rather than compute an angle and vector, so I thought I would try that.
I set it so each frame the boomerang subtracted the location of itself from the location of the target, and whether that was positive or negative it would either add or subtract the nudge value to the velocity. It did that for both of its axis.
But this caused problems where sometimes the boomerang became erratic on one axis, presumably because it overshoots its destination and repeatedly overshoots itself trying to hit that target.
I tried to reduce this by having it reduce the nudge amount proportionally to how far away it is from its target, once it was within a certain range, but this only made the erratic corrections follow a larger arc.
I've been thinking this over and I just can't figure out how to arrange this. What sort of logic should I be following? What sort of design should use?
I greatly welcome any other ideas I could try.