Throwing an object help

So recently I’ve been trying to get my player character to be able to spawn a bomb & throw it in a similar manner to the Legend of Zelda games, although since I’m making a sidescroller game I guess it would be more similar to the Bomb ability from the Kirby games.

Anyways though, so far I’ve managed to successfully get the bomb to spawn in my player character’s hand, as well to detach when the bomb button is pressed a second time but I haven’t been able to get the player to actually the throw the bomb. Instead the bomb just detaches from the player character’s hand and falls onto the ground in front of the player.

Bomb Throw blueprint:

I’ve tried various different setups to try and get the bomb to move through the air but nothing I’ve tried so far has worked. The only time I’ve managed to get the spawned bomb to fly through the air was when there was a overlapping collision issue between the bomb and something else. The problem though is that would result in the bomb being hurled through the air at ridiculous speeds, often in different random directions.

Ideally, the bomb should be thrown in a consistent overhead arc like :

345859-bomb-example.png

Although I should also mention that I was also planning on the player character being able to throw a bomb in a straight line if they toss it while running at full speed, as well as being able to drop the bomb on the ground in front of the player character kinda like how it does now. I thought I should include information as something to take into account for anyone willing to help out me with problem.

Any help whatsoever would be greatly appreciated!

Hello! Do you try node Add Impulse | Unreal Engine Documentation
?

Yeah I’ve tried following setups that use that node, but didn’t it make any difference.

Anyways, I made some modifications to my current setup after following a different tutorial on grenades, and now my character can actually throw bombs… sometimes.

Unfortunately, overall things are still largely the same, just now my character will occasionally throw a bomb instead just dropping on the ground, usually when the character is in mid-air or standing on a ledge.

One odd detail I’ve noticed after making the changes to my blueprint is that now when the bomb detaches from the player instead of just dropping to the ground like before, the bomb instead slowly drifts downwards towards the ground. It appears that the bomb’s movement is being impeded by the player character’s mesh and I’m not sure why that is.

Given the seeming randomness of the player character’s ability to throw bombs, along with the weird dragging issue, I’m starting to think that its not the bomb throwing blueprint that’s the problem. I can’t say for certain, but it seems to be more of a collision issue between the bomb and the player character’s mesh. Maybe the bomb’s momentum is somehow being obstructed by the mesh of the player character and that’s why the bombs are just dropping on the ground?

I honestly don’t know, I’ve tried changing the collision settings on the bomb blueprint but nothing seems to work.

It’s probably because lack of force - try some higher values to test if it even happens

Do you have it to be simulating physics since the beginning? If no - you hafta enable it, if you do - maybe you stop it at some point via other part of code

Also what’s the forward vector - you sure it’s always matching your character direction or you manage to rotate it in some other way?

The piece of code from @Kehel18 is actually a proper piece of code so for my eye it’s lack of force or rotation/velocity/physics issue

Did you touched the ‘Drag’ section? There are two different drag forces and it may be that lateral drag is at a high value - will prevent the object to move horizontally so well

Okay, now I’m almost 100% certain that the problem is being caused some sort collision issue and not a problem with the blueprint itself.

After some testing, I’m now able to throw bombs properly 100% of the time, provided that the player character is in a falling state when the bombs are thrown. The only possible reason I can think of on why is the case is that when the player character is falling, their arms are outstretched away from the body, away from whatever it is that is obstructing the bomb’s trajectory.

Whatever is causing the obstruction is definitely part of the player character but I don’t know what part. It could be main mesh itself or it could be the melee weapon hidden inside the player character’s body when not in use. I’ve gone through the collision channels on the player character, as well as almost every collision preset within the Project Settings again and again and again to no avail, wasting hours of my life and slowly driving me insane.

In theory, if I added the proper throwing animations I’ve yet to incorporate onto my character, it would position the bomb away from the player character’s body, keeping it from having its trajectory obstructed by whatever is causing the problem. However, I’d still like to fix the underlining problem rather than trying to work around it but for the time being I’ve run out of ideas on what I can do.

Just try that node on separate bomb actor to check it is Ok with bomb itself… And if that is true then move on your primary case…

So I finally managed to get my player character to be able to throw bombs. I swapped out the Set Physics Linear Velocity for Add Impulse but I still couldn’t throw bombs properly until I I found that making the bomb’s static mesh the new scene root component fixed the issue.

346105-new-sceneroot.png

I have no idea why that worked but it did.

However, the collision issues still persist, as when the bomb comes into contact with the player after being thrown, the bomb’s momentum is nullified and the bomb drops straight to the ground, sometimes with the bomb getting “caught” on the player and very slowly drifting to the ground just like before.

However, seeing that I originally created topic for spawning & throwing projectiles and not collision issues, I think I’ll just consider topic case closed and create a separate one for the collision issues I’m having.

Thanks for the help.

2nd Screenshot - you get velocity of which actor?

If it’s the player and you stay still you’ll get 0, you multiply velocity * 0 - it also returns 0

So there’s no force being added here

You get actor up and right vector and get the middle of it, you can just get forward vector, add 45 degrees to (probably) Y axis

You said you checked collision channels and you have a hidden component - make sure it’s collisions are disabled when it’s not visible (change at least to overlap if needed but not block)

Also putting some print strings on empty Execution Nodes is a good practice to check what’s happening with the code, or just use Debugging, also when you run the game in separate window you’ll see the BP workflow ;]

I found that making the bomb’s static
mesh the new scene root component
fixed the issue.

is 101 of the PhysX sim and the way welding works in UE4; a must if you want to get a reliable transform.

If it’s the player and you stay still
you’ll get 0, you multiply velocity *
0 - it also returns 0

It’s fine and is optional if you want to preserve relativity:

Link to thread:


@Hungry Moogle

You’re running into issue because of the way you handle entities simulating physics. The Detach Keep Relative of an actor whose root is simulating does who knows what to the whole thing. I am half expecting that the root is getting some kind of phantom offset.

As an example: imagine a scenario where you have an actor with 5 simulating static mesh balls, all rolling away in a random direction with different velocities. What do you think is the transform of that actor? And what happens when you want to detect actor overlap. It really complicates thing.

I know you want to do things your way but since you’re running into issues - why not use the example I posted - it seems to be working and has already pushed you a bit further towards what you need (I hope!)

Is there any additional functionality that’s needed?

For a starter, do not detach that actor, there’s no need - it’s simulating physics anyway. As a bonus, the bomb could do :

Might be relevant if you want to easily find out whose bomb hits what without creating hard references!

Hit character limit with my rant :wink:


Apart from that, I’d do the whole thing with the Projectile Movement Component instead - much more reliable than pure physics sim and comes with a TON of functionality and utility. And, if you must use physics with Projectile Movement Component, it actually allows you to override the component’s behaviour to an extent:

 * Normally the root component of the owning actor is moved, however another component may be selected (see SetUpdatedComponent()).
 * If the updated component is simulating physics, only the initial launch parameters (when initial velocity is non-zero)
 * will affect the projectile, and the physics sim will take over from there.
1 Like