Log In  

Does anybody have some methods for creating a boomerang action effect?

You know...player throws a boomerang and it eases out to X distance, hangs there a sec, then comes back to the player regardless where they are. Zelda-style.

I imagine it's a lot of atan2() math and something like that...but wondering if anyone has something they've already made and are willing to share before I spend weeks trying to figure it out. Thanks!

P#37906 2017-02-27 20:35 ( Edited 2017-03-04 06:23)

Well lets make this a learning activity. Start with the basic out and in motion. You want to record your destination and begin moving toward that. This is the easy part as that's a straight line. Next you want to return to either the start location (real boomerang) or the thrower (Zelda style). If you want a real boomerang, just move back the way you came.

Now for the more fun Zelda style boomerang, you need to keep tabs on the player and move toward them. You'll need to take the atan2 of the vector pointing at the player which you can get by subtracting the boomerang X from the player X, and same for Y. This gives you the angle in radians (normally) and you'll use your geometry to move a specific number of pixels (the boomerang's speed) along that angle.

The last part you'll want to despawn the boomerang when it's close to the player using the Pythagorean theorem. This is because the boomerange won't always be on an exact pixel location on the player so you just pick it up when it's close.

I can help you with the math but I'd like to see what you come up with. Also I'm on my phone right now at work.

P#37956 2017-03-01 00:35 ( Edited 2017-03-01 05:35)

there's this sample by Krystman about shooting straight at a target:
Sample Code: Angle Calculation
I did add a grenade launcher to it. maybe you could pull something out from this, like shoot straight and come back in gravity mode. or both in low gravity (wind) for a curved attack (reverse gravity/wind between attack and return).

edit: oops, there's no auto-guiding in the above...
edit2: added a homing missile :)

P#37966 2017-03-01 08:39 ( Edited 2017-03-01 15:24)

@richarmeleon - Thanks for the insight, it's exactly what I needed to help the process. I'm all for figuring out myself, just needed pointed in a good starting direction.

The moving toward a point isn't issue as much as the Zelda return that follows the player. I have 50% of the solution already in my head, now I have the other half :)

P#38012 2017-03-03 13:15 ( Edited 2017-03-03 18:15)

@morningtoast glad I could help.

P#38029 2017-03-04 01:23 ( Edited 2017-03-04 06:23)

[Please log in to post a comment]