3D Bow in Godot

Godot Version


I need help with making a bow in Godot 3D. Funny thing though… I don’t know much about physics and such such. Would anyone mind to lend a hand? Thanks!

(godot version: v4.2.1.stable.official [b09f793f5] if you can’t see godot version.)

What part are you having trouble with? There’s a whole physics engine at your disposal, so if you want to make an arrow that gets shot and flies in a parabola, all you need to do is spawn it at the starting position and give it a force to launch, then the physics do the rest.

Hey! I’m having issues with making the arrow start flying, and making sure the Arrow is in the main scene. (Because I have the bow in my Player scene which may be kinda dumb)

You can start from get_tree().root and use get_node() and find_child() and get_children() to navigate down the tree, or you can use get_parent() or ".." in get_node() to go up. Once you have a reference to your game world node, you can add_children() from it to add your arrow.
I assume your arrow is a RigidBody. You want to first set the orientation to the same vector your camera is using (assuming a FPS) and then use apply_central_impulse() on that same direction with a rather large force value. This will push the arrow and let it freefall. You do all this in one frame, but you may want to apply the impulse in the physics thread, so instead of having it directly in the arrow creation code, you can just give the arrow a boolen var for just_got_shot and then in the _physics_process() of the arrow you do

if just_got_shot:
	just_got_shot = false
	apply_central_impulse(direction.normalized() * initial_force)

This is the simplest way, but of course you can then add inaccuracy and bowstring strength and other factors to it, have wind affect it later and whatnot. This is the very basics.

Nice! Thanks for helping me.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.