Throwing a weapon in blueprints

Hi! I’ve been trying to make some sort of a weapon that you can throw to the direction of your character ( away from it of course ) in a boomerangy way in blueprints and I haven’t gotten really anywhere. Right now I’m using an arrow component and just a static mesh parented to it(I have an actor blueprint of my “weapon”). First I think I have to get the location of my character and then somehow using maybe a timeline to get it thrown out into the world along the arrow component’s forward vector and come back by getting my character’s location at that time. I don’t know if this is anywhere near the right way of doing this and I can’t figure out how to actually do this in blueprints. I have problems especially with timelines, I know a little bit about them but I don’t know how to get a location on all the three axis. So if someone could maybe show a picture of a blueprint doing this kind of thing I’d be really happy, any help will be appreciated!

You actually don’t really necessarily need a timeline.

You could just create a projectile which is provided a vector and your character. Get the forward vector for your character and input self into the character field and inside of your projectile class just update the location for x seconds adding the vector to the current location.

Once the time is up get the vector between the projectile and your character and add that one to the current location deleting the projectile on character hit.

Thanks for your answer! But I still can’t quite figure it out, here’s my weapon class blueprint I poorly created from your advice, I obviously missed something because the cast just fails and there must be some other problems too:

Could you maybe show a picture of doing this right or be a little bit more specific, I’m really new to this, thanks!

I examined your comment more closely and this is what I came up with. It still doesn’t work though so I did something wrong again, it just seems to spawn the projectile in the scene outliner but I can’t see it anywhere.

I’m sorry I didn’t reply yesterday.

For some reason I couldn’t comment and it was already quite late.

I have the comment saved though on my desktop. Full 2k characters. A detailed explanation with pictures of what I meant. Fully functional. I tested it on a project of mine.

I’ll add the comment later today. That should clear up things quite a bit :wink:

Oops, just forgot to assign my boomerang to the components, now it works somewhat correctly! I also changed things a bit in the blueprints.

This is a suggestion how it could work. I’m not using a timeline as it is quite restricted.

Inside of your Boomerang I set it up like this:

Keep those two nodes I marked in mind. They will provide an additional pin when spawning it. Just add self reference there.

Then just like in my picture create a “Event begin play” and get the forward vector of character.

The vector is created by first multiplying the “Missile Speed” variable with delta time. Basically that makes sure the boomerang flys always at the same speed no matter the frame rate.
I multiply the vector which we got in the first picture by that (it will have the length 1). Simply add the result to your current location.

The result is a steady movement in the direction your character was looking when you spawned the boomerang.

Once time is smaller than 0 we need the boomerang to come back to the player:

Take the player location subtract that with the actor location of the boomerang. Like that we get the directional vector from the boomerang to the player character. Divide this vector by it’s length so get again a vector with the length of 1 and multiply that again with missilespeed * deltatime.

You will have to destroy the boomerang once it’s back at the player. You can check for an actor hit and compare the other actor to your character with the “equal” node or something like that.

You can also enable sweep while making your boomerang flying away and check the boolean output with a branch. If it’s false and then directly making it fly back. This will cause it to come back when it hits something. There’s a lot you can do additionally.
Also I would recommend to add the “Set time” before the branch. Otherwise the boomerang will fly further the slower your framerate is :wink:

Hope this helps.

Cheers,

Erasio

That definitely helped! Thank you so much for taking the time to write that answer! This is how I handle my collision now:

There seems to be a new problem though:P but now I think it has something to do with my collision settings, do you happen to know anything about those? Right now when the boomerang comes back it sometimes tends to collide with my character and push it away and then destroy itself but sometimes it works just fine.

Well the most obvious solution would be to use overlap.

It would allow you to throw that thing through enemys and instantly get rid of all collision issues with your character.

However usually unless you apply force you should not be pushed away so my first assumption would be that you have a mesh or something with collision which also blocks but doesn’t generate hit events.

Could you check if that is the case?

There is a setting for each component “Generate hit events”. It should be enabled for everything which could touch something or to be sure for now just enable it for everything which has in the collision settings “block all dynamic”, “block all” or any kind of block for anything.

Okay did you mean something like this?:

It still collides with something though.

Yea. This should simply generate “Event begin overlap” which you can use exactly like you did with event hit (it only outputs a “other actor” and not a hit result but it’s enough to compare).

Though none of your components has the generate hit events enabled which would explain why it didn’t hit earlier.

But this time it shouldn’t be able to collide at all…

Oh I misread it, I thought you meant just the “generate overlap events”. It still doesn’t seem to work with the generate hit events enabled either. Is there something special I should do with how I handle my collision in the BP?

The thing is I have no idea what’s going on. While having “Overlap” on it should be impossible to impact your character at all. At the very least it should not impact the position.

Same here :stuck_out_tongue: I know that should work but there’s probably just something I didn’t notice, I’ll try and get the information somewhere else. But thank you for your help, I really do appreciate it!

I read all of this and i tried what you did but it doesnt work :confused:

could you tell me how did you get that Hero variable. Im using 4.6.1 and it has Character instead of it but then the projectiles dont work

Yea I struggled a bit with that one too but the character type variable seems to work just fine in my project though! Did you check the editable checkbox to make it public? Maybe it has something to do with that:P

Did you also notice the expose on spawn checkbox?

I did and it didnt work :confused: Im a noob at the technical part of UE and I only began in October this year :stuck_out_tongue:

can you give a link to the BP of the same you made, if it works that is.

Im a noob too, I started in November :stuck_out_tongue: so I dont know if I can help that much but ill try. Here is my current blueprint for the projectile

It still needs some work with fine tuning but the idea works well.
And here is the part of my MyCharacter blueprint that spawns the projectile

By the way did you remember to set your projectile class in the SpawnActor node? I dont know if this helps but I hope it will:P