How to make a boomerang for a 2D sidescrolling game?

I was wondering if anyone could help me figure out how to make a boomerang for a 2D sidescrolling game. I’ve tried looking on YouTube for tutorials but I haven’t been able to find anything. Basically, I want to make a boomerang that when thrown travels in a straight line for a short distance before it turns around & returns to the player. I also feel I should clarify that when I say “return” to the player I mean that the boomerang that will home in on the player’s location. For example, if the player throws the boomerang and then jumps up onto a platform the boomerang will then travel upwards to the player on the return trip.

I have anything else ready, I have the character’s throwing action all set-up and I have two sets of various character animations for both the character holding/not holding a boomerang. At this point, I’m pretty much just missing the boomerang itself being thrown.

Thank you in advance!

it would help to know more specifically what you’re missing.
what i’d do is in the boomerang add the movement logic.
you could try a movement component and add a couple of positions.
or you can do it manually.
with the movement component you could:

  • when launched, calculate the end point, set it on the movement component and activate it.
  • then when the movement component is finished. calculate the return position and re-activate it.

though if the player moves while the bo…ng is returning, you’ll have some issues. either making the b…g change its destination (will look magical) or something else.

My understanding is that you already have animation and logic for the throw. But you wanted the boomerang to come back to the character after it travels in a straight line, Y + or Y - in side scroller sense.

The way I achieved this…

In your character bp -

Make some variables (boolean) - ThrownBoomerang? , Facing RIght? (Which I assume you work out where to set that one, optional is “DisableAll?”

  1. First check that ThrownBoomerang is false

  2. Set ThrownBoomerang to True

  3. Optional - set Disable all to true

  4. Play your throw montage

  5. The delay here is for optional adjustments along with the height adjustments on spawn to make it “look” right. Also set disable all to false off the completed of the animation montage.

  6. Spawn your Boomerang actor bp

In your Boomerang actor bp -
Add a rotating movement component, I set it to - 500 on the Y in the video

That number is the speed the boomerang will rotate, for the other direction just reverse it. - or +

  1. Off of an Event Begin Play - Spawn the sound and get a ref to it - https://file.io/2qCCZ8VgkY1w

  2. Cast to your player character and get a ref. Or not, and cast again later for absolutely no reason at all!

  3. Check if your character is Facing Right? This will determine one of two different Timeline driven pathways.

  4. Add two timelines, I will open one of them ( the top one) and show you the values in the vid. Essentially, the bottom one will be mirror opposite values, in this case on the Y. This is so the boomerang does not come to a halt instantly. And these value and curve can be messed with for better results. This is just what I come up with quick. You will add a float track, and the length is going to be how far out you want the boomerang to go before the return action.

  1. Add two add actor world offsets, split struct the pin and plug each respective timeline into the Y.

  2. Bottom half of pic, off the Event Tick, get your character ref (suggest making it a validated get) or cast again just because you can and stuff.

  3. Here I used a gate that starts closed, but you could use a boolean instead. Essentially this gate is going to open when our timeline’s have finished off their complete output(s).

  4. Add actor world offset, here I added on the Zed to make it look like returns to the hand or head.

9, Check if the boomerang mesh is overlapping with the player character mesh, and if it is…

  1. Set ThrownBoomerang? to False

  2. Stop the sound

  3. Destroy Actor

2 Likes

Thank you so much for this! I greatly appreciate the effort but unfortunately I haven’t been able to implement your solution due to a major issue.

You see your solution is based on the boomerang spawning out of thin air which is a problem for me because the boomerang in my project is basically a part of the thrower. The boomerang is always visible at all times due to the thrower carrying it with them in all of the animations I’ve made so far. So I need the boomerang to detach from the character’s hand when thrown rather than spawning out of nowhere.

I’ve tried to see if I could implement your solution in a modified manner to work with my current setup but I haven’t had much luck. When I try to detach the boomerang from the character, the boomerang disappears. On top of that problem, I also can’t figure out how to make boomerang move as I can’t attach the boomerang as a target to the AddActorWorldOffset node. Instead the player character ends being the target by default and ends up being hurtled forward as a result.

What can I do about this?

  • make the boomerang a separate actor and keep it attached with the Child Actor Component

or

  • instead of Add Actor World Offset, use Add World Offset and target just the component you need
1 Like

+1 to above. but also:

don’t use keep relative on detach. use keep world.

1 Like

Sounds like the title of a metal song,.

Yeah, you can use the same boomerang. That method will involve detaches and carefully timed use of delay to let it go from the hand and look right. I essentially copied the boomerang bp, stripped out the rotating movement component and copied its logic and disconnected it from fire. Tried to apply the same logic in the character bp. In your Event Begin play, spawn the boomerang, and attach it (preferably to a boomerang socket in the right hand). After you spawn it promote its output to a variable / OBJ. However you normally throw it, this is where the copied logic from its actor bp comes in and tries to simulate threw detach and attach what that other bp was doing. I used a set timer to simulate a fast firing event tick because in this bp my event tick was in another country. I had to choose .001 for its rate else it did not look smooth, but it would look as smooth as before with an event tick.

1 Like

Alright so I finally managed to get the boomerang working with the help provided here, albeit with some issues that need to be resolved.

#1.) The first issue is that when the boomerang returns to the player character it gets stuck to the player character instead of returning to their hand.

The issue seems to be that everything after the AddWorldOffset node isn’t working for some reason. It might be because I wasn’t able to hook up the boomerang variable to the Is Overlapping Component node in the same way as usa423’s example but I can’t say for certain.

#2.) The boomerang only goes right even if the player character is facing left.

In this case I almost 100% as to why this isn’t working properly. The ‘Is Facing Right’ Boolean variable doesn’t actually do anything as I don’t know how or where I’m supposed to set up the underlining logic for the Boolean to actually work.

#3.) The boomerang travels too far when thrown, going off-screen before it makes its trip back to the player. I tried cutting the timeline for the boomerang’s movement in half which did reduce the distance that the boomerang travelled but resulted in a weird issue where the boomerang would get caught on objects on its return trip. This is strange because the boomerang is normally able to move completely unimpeded, including through solid objects so I’m not sure why halving the timeline is effecting this.

#4.) And finally, related to the above, I mentioned that the boomerang currently is able to move through all objects. Generally, this is fine as I want it to be able to cut through enemies & to not get caught on solid objects / scenery while its returning to the player, but I would also like for the boomerang to reverse direction and return to the player as soon as it hits a wall rather than travelling through it.

Can anyone at least help me figure out why the boomerang isn’t properly re-attaching to the player?

What is it doing then, precisely? Try changing the Location Rule to Snap To Target - does it help?

1 Like

The boomerang sorta sticks to the player instead of properly re-attaching to the player character’s hand upon returning. The reason why I say that the boomerang “sorta sticks” is because in reality the boomerang isn’t actually attaching itself to the player but rather its just the boomerang following the player’s location. This can be seen when the player character jumps off a high ledge, resulting in the boomerang lagging behind the player character briefly before it catches up.

In addition, the Boolean variable that supposes to disable the boomerang from causing damage once it returns to the player character isn’t working as well.

What this suggests to me is that the Branch node condition isn’t working, resulting in everything that comes afterward to not work.

I’m fairly certain that the problem is related to the ‘Is Overlapping Component’ node that serves as the condition for the Branch node but I don’t know how to fix it.

Set up breakpoints and see where the data flows. Or print string. Or use the debugger to observe execution flow:

image

Once you know which part is failing, do tell. Otherwise we can only guess.

Do you really just eyeball stuff rather than actually test what is working and what is not? Living dangerously!

1 Like

Okay, I tried using a Print String message and a message only appears when its placed before the Branch node and not after. So I would say that its almost definitely the Branch node that’s not working.

1 Like

You’d need to look into the collision settings and determine why it does not work. On topic, different angle - any reason why you’re not using onBeginOverlap instead? It would be cleaner and you would not need to test for overlaps every frame…

1 Like

So based on your suggestion I tried separating the boomerang re-attaching to the character’s hand part of the coding from the rest of the boomerang returning to the player coding.

Unfortunately though, this has somehow made things worse than they were before. The boomerang now no longer returns to the player and instead just flies off in a straight line.

I now find myself with absolutely no idea on what to do now as none of this makes any sense to me. There’s nothing in the code that I moved that’s related to the boomerang’s return movement, so I don’t why moving it has caused it to stop working.

I tried adding a Print String node and a message does appear indicating that the code is working, so what on earth is going on?

Great, so now on top of my blueprint not working, I can’t get the breakpoint debugging tool to work either.

The above breakpoint has been added to a part of the blueprint that works but there’s no sign of activity when there should be.

You hit the breakpint. It works then. If you can’t progress past it, the bool is True.

I have a :boomerang: like thing somewhere. Will dig it up. Stay tuned.

1 Like

So with the breakpoints enabled, the program can only go as far as the Branch node & no further. Evidently, the Branch node works but not the Set Boolean node that comes after, which doesn’t make a whole lot of sense to me. If anything that’s causing a problem, I would assume that its the Branch node.

Unfortunately the breakpoint also doesn’t help explain why disconnecting the Branch node completely breaks the boomerang’s ability to return to the player.

aaa

False advertisement, could not find it. But it was similar to this devilishly simple thing that still offers quite a bit of customisation:

  • the player spawns a new actor:

This will need to be adjusted if you need to hold it at all times instead.

  • the throwing logic goes into the projectile:

The gist:

  • the boomerang is an actor with a spline component and a static mesh

  • the spline lives in world space and does not move with the character:

  • we only move the very last spline point during TL Update so the projectile can return to the socket accurately

  • the timeline moves and spins it in local space

  • the trajectory is described by the spline:

You can add or remove points to make it fly pretty much any way. Project link.

1 Like

I appreciate the suggestion but the current setup I have of the boomerang travelling in a straight line a certain distance before homing in on the player character’s location when it returns is exactly what I want.

Also the fact that your setup doesn’t address how the boomerang detaches/reattaches itself from the player is a major issue as that’s basically my biggest problem that needs to be solved.

On that subject, since I haven’t been able to figure out why the boomerang won’t automatically reattach to the player character’s hand upon returning to the player character, I decided to create a button input for playtesting/problem-solving purposes that when pressed would manually reattach the boomerang to the player character’s hand.

Pressing the button causes the boomerang to reattach properly which is good but the boomerang isn’t properly rotated causing the boomerang to be sticking out the player. This is turn causes problems with the boomerang being thrown again as the boomerang’s momentum appears to be being dragged down by overlapping with the player character’s model.

In fact, I’ve noticed that when the player character throws the boomerang in general, the boomerang isn’t rotating properly.

For reference, this is how the character throws the boomerang within Blender where I originally created all the animations.

Meanwhile, this how the same animation looks in Unreal Engine.
boomerang_problem_8

As you can see, the boomerang isn’t being properly positioned for when its thrown, resulting in the boomerang spinning in the wrong way as well as it being held in the wrong manner upon returning.

Does anyone have any idea on why the boomerang isn’t being properly positioned like it did in Blender?

As for the problem of why the boomerang isn’t properly reattaching itself to the player character, at this point I’m almost 100% certain that the culprit lies here with the ‘Is Overlapping Component’ Branch node condition.

When the re-attachment part is separated from the rest of the code and instead handled by a button press, it works, aside from the boomerang being in the wrong position but as I’ve established above that’s not because of the re-attachment process.

The problem is that I don’t why the Branch node condition isn’t working and I really need somebody to identify why this is happening and what I can do to fix it.