Top Down Zelda-like Picking Up & Throwing System

Godot Version

v4.2.2

Question

Like the Title says, I want to make a system where the player can pick up and throw items like a Zelda game. I havent found any tutorial that works for Gadot 4, so what are the steps I need to do? I already have a raycast2d working on my player.

This is a bit of a vague question, because implementation will vary wildly depending on what you have going on with your player. That said, here’s some non-code concepts of how you could do this.

First, you’re going to have some kind of object that can be picked up and thrown. I would recommend you make a basic Throwable class and then make specific versions of it like Rock and Pot. This means you can modify any behavior about throwing these objects from the Throwable class, and just use Rock and Pot to change things like the default sprite and damage done if it hits an enemy.

Secondly, you’re going to need a control to permit the player to attempt to interact with a Throwable item. Exactly how you set this up can depend on your game, but for a basic test just give yourself a button that is “Interact”.

Third, the Player class will need to listen for the Interact action. When that happens, use your Raycast to look in front of the player. Remember that the length of the Raycast will determine how far away the object can be and the player will still be able to interact with it.
If it collides with something, you want to find out if that object is a Throwable, so you use the Object.is_class(“Throwable”) function to see if it’s a Throwable.
If it’s not a Throwable you could still use the Interact to decide to do something with it - like read a roadside sign - but we won’t address that right here.

If it is a Throwable then you now know that the player has interacted with a Throwable object that is close to them.
From here, a bunch of stuff needs to happen:

  1. The Player presumably needs to update to a “Carrying” state, which probably means a switch to a “Carrying” animation set as well as some status variable like a Boolean.
  2. The Throwable object will need to be set to follow the player around. You might choose to re-parent it to the Player, or just mark it as “carried” and update it’s position to the appropriate Player + offset position constantly.
  3. You have to decide what input will cause the player to throw the carried object. If the Player is in the Carried state and sends that input, you’re going to make the Throwable act like a projectile (look at bullet tutorials, for example) and move away from the player. I assume the Player will have a “Throwing” animation that runs before going back to “Idle” or whatever.
  4. The Throwable needs to not be “Carried” anymore, and should move your desired speed/time/distance before either breaking (that it fell to the ground) or striking an object (enemy, wall, etc) and breaking as a result. Again, much like a projectile hitting anything else, this can do damage.

And finally, keep in mind all the other things you have to address when you add this:
What happens if…

  • The player is Carrying and wants to set it down without breaking it?
  • The player is Carrying and wants to swing a sword instead?
  • The player is Carrying and wants to move to a new scene?
  • The player is hit by an enemy while carrying?
  • The player tries to interact with a second Throwable while carrying one?
  • What happens if a Throwable hits a Throwable?

etc.

1 Like

Thankyou, yeah sorry for the vagueness lol. Wrote while i was away from my computer. Thankyou so much, this is really helpful!

1 Like