How can I make a throwing mechanic without using physics?

I’m currently working on making a 2D co-op puzzle platformer and one of my characters can pick up, drop and throw items. So far I’ve been able to get the pick up and drop mechanics working but I’m not sure how to approach throwing. I looked at tutorials but they all use physics which I want to avoid using. I don’t want objects bouncing around everywhere and I want the second character to be able to jump off of objects while they are being thrown. I also can’t pick up objects that simulate physics for some reason.

Here is my code for picking up and dropping objects.

This is what I have so far for the throw mechanic

I figure that for the throw, on Triggered should calculate the arc of object with X amount of force applied and that on Completed should, release the object → apply force → follow the arc. I’m pretty new to blueprints so I’m not sure what nodes to use for this.

Hey @ScoutAX! Welcome to the forums!

So in order to use forces… you have to simulate physics. No way around it.

When you pick it up, you can set simulate physics to FALSE, so you can actually carry it, then when you throw, you can set simulate physics to TRUE, then apply your force.

As far as not wanting things bouncing around on your level, make sure you set an appropriate mass. More mass- harder to move- less likely to get pushed around. :slight_smile:
Hope that helps!

1 Like

Hi! Thank you for the response! :slight_smile:

I tried toggling simulate physics but it still wouldn’t pick up the object. Turning it on and off works but the object just sits on the ground after I interact instead of attaching to the socket. Any ideas on what could be causing that?

Rather than use forces, is there a way to make the object follow a set path through world space to give the illusion of throwing without making an animation? I have different objects that I want the player to be able to throw, some of different sizes/shapes.

Also as a note I ended up moving the pick up and drop code to functions within the object itself and am just calling them from the character now.

This is what physics was specifically invented for- to get around the pages and pages of math and possible parabolic equations.

You’re turning it OFF → Attach, ON->Throw, correct?
Because if you turn it ON → Attach, it’d just fall to the ground.

If you’re using “Weld Simulating bodies” on your “Attach Actor to Component” you’ll want to make sure that is NOT ON. :slight_smile: It can cause issues when welding things that aren’t simulating physics- and your pickup item nor your character should be simulating physics (until you throw the item at which point it isn’t attached).

Also to get your arc you should try “Suggest projectile arc”. :slight_smile:

You could use a timeline with a 2d vector, one value is for the X and Y axis and the other is for Z. Run the timeline when something is thrown and multiply the XY value by the throwing pawns forward vector and plug it into an add location node, the Z value doesn’t need multiplied.

I got the throw working!! I had been turning it on before attaching and turning it on when throwing was the right thing to do. I do still have the same issue of being unable to pick up the object after throwing it though. The game still registers me as picking it up and being able to drop/throw it but the object doesn’t attach to the socket. Also I now have an issue where if there are multiple objects in the level I can only interact with the first one I placed in the level. I didn’t have the issue before so I’m not sure what in the new code could be causing it.

Here is the code I made for throwing


No matter how much I edit the Z value in the velocity calculations the height of the throw never changes. As of right now I can only throw it forward and not up. Not sure if there is a different node I should be using.

Here is the code I made for aiming


For the aiming I didn’t use Suggest Projectile Arc because the node description said it was used to calculate the velocity needed to get from point a to point b, and since point a is the players hands and point b could be anywhere in the level I wasn’t really sure what to do with it. The way I am doing it now though causes the game to lag for a solid second before the object is thrown so I’m looking into other ways.

I also made this loop for On Tick that will check if the object is on the ground and if so will disable physics

Thank you so much for your help so far, I really appreciate it :grin:

1 Like

Turns out even with the throwing/aiming disabled I still cant interact with multiples of the object in the level. It might have something to do with me moving the code for pick up and drop to the object itself but I’m not sure why that would cause this.

Yeah, I was looking through what you posted, and noticed there’s no pickup code, no check for that in any way, we need to see the pick up code to be able to help there.

Show us how you’re getting “Toss Reference”?

Also, what is the value of “Speed” vector? If it has a 0 in Z that’s going to make it travel horizontally regardless of your vector, because of the multiplication. Lots of things here it could be, so let’s get to it! :slight_smile:

Sorry for the late reply, have been busy the past few days.

Here is the pickup code. I have it as a function in the object itself and I call it in the character on the button press

As for the Toss Reference, its a reference to the character and I get the reference in the object on begin play

This is what I’ve had the speed variable set to. No matter what I set the Z value to the direction doesn’t change. The only time I see change in the throw is when I edit the X value

Okay! So firstly- it’s looking like you aren’t DETACHING that actor from the socket. SO- if you already have attached something to the socket, you won’t be able to do it again because it’s still attached! It just can’t snap anymore because physics is on, so it looks like it isn’t- but it is! :slight_smile:

The reason you can’t affect the Z value, only the X, is because of your two vectors you’re getting the unit direction from. It’s likely just (X), 0, 0.

Try ADDING to the Z of the vector and inputting that, because by multiplying you’re just getting Z*0, which will always be 0.

Try that stuff and get back to us!

Adding the Detach from Actor node to throw didn’t do anything, even tried it in the On Tick loop I have on the object. I’m almost certain at this point that the issue has to do with the object being given physics since the detach works fine with the drop mechanic I’m just not sure why it doesn’t work even when I remove physics.

Adding to the Z of the vector worked though! I was able to get the object to be thrown up :grin:

Do they not have physics when you pick them up in the first place?

Have you tried turning physics off as the very first thing in the pick up code?

No they don’t have physics enabled initially.
Just tried having it enabled at the start and disabling it on pickup and it says I am holding the object but doesn’t attach it to the socket.
Also, when I have physics enabled from the start if I try to put the object down after picking it up it wont let me pick it back up again.

It may be the order in which you have the nodes. Would you mind showing the code when you have it as:

Starts with physics enabled
turn off physics before pickup
Turn on physics with throw
?

Here is how I had the code set up when trying it out.

On Pick Up it disables physics

On Throw it enables Physics

Once it hits the ground it disables physics

HMMMMMMM HOLD ON NOW.

I’m seeing a lot of “Cube” set simulate physics, which is a component… Whaaaaat about the ACTOR?
What is the root component of the cube??

If it’s a collision component, try setting that to visible, and NOT hidden in game- we want to see those wireframes!

Then go test everything! I’m thinking maybe the component is getting thrown but that’s the only visual representation- but you’re trying to pick up the ACTOR, which would be located at the root component!

IT WORKED!! :grin: :tada:

Changing the root component to Collision and then calling that everywhere I called cube made it work!
image

I am getting these errors whenever I stop running the game but I’m not sure if they matter

Thank you so much for your help! I couldn’t have done this without you :grin:

1 Like

These are hitting because of times when you’re trying to do things but your settings say you can’t, but don’t worry, that’s by design! They’re supposed to be there to help you, it’s assuming you want something different.

One thing you can do is try making the cube the root instead!

Glad we got it all worked out! :slight_smile:

I’m gonna mark this as the solution but I wanted to update you on my progress. I ended up changing all of the pick-up, drop, aim and throw code back to the player instead of the object itself so that pressing the button does the thing rather than call the function from the object and it fixed the issue I was having with interacting with multiple objects in the level.
I really can’t thank you enough for the help :grin:

1 Like