The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

+1 vote

i wanna make an arrow movement, the arrow need to be really fast and stop immediately on the wall (like it has the arrowhead pierce in the wall)

in Engine by (78 points)

Could you provide more details? What do you mean by "arrow movement"? Are you using a RigidBody2D or an Area2D for it?

I hope it helps, I believe is an Area2D, have a look at this tutorial, it may you have seen it or not.

NOTE: I am not sure if is allow to post links like the above, I have nothing to do with the author, please let me know if I ned to remove it.

I wanna know what node i should use for this, I already know how to instance the arrow when I want, i just need to know the best way to move it forward and make it stops on the wall

it is fine to share links, however, I had already seen, it does not help much

For stuff that needs to move, yet also needs to interact with the surrounding collisions, I use a KinematicBody2D.

1 Answer

+1 vote
Best answer

Answer to question:
Both options are good, but in your case I'd use Area2D. If you're using an arrow, than you'll probably have to update the global_position of it, because otherwise, if you move the parent node, it moves too. You'll need to make your own collisions, but I think, that haveing a RigidBody2D would be unnecessary, because you won't really use physics for it's movement.

My advice:
I think you should use a State Machine, because you can set states, so when you shoot the arrow, it's in a moving state, if it hits something it's in a stopped state.
You can obviously make the script (and the state machine) really simple, but I recon' spending some time with it because you can reuse it, and it makes you code be nicer.
I only know this tutorial, but you can totally apply it to kinda everything:
this is a part of the tutorial:

but if you don't want to have complexity to your arrow, then I made a simple state machine inside this little code section:

extends Area2D

# Varaiables for moveing
var move_direction = Vector2(0,0)
export(int) var speed = 10
var states = ["fly", "stop"]
var current_state
var pos
# Damage
export(int) var dmg = 10

# When I spawn the bullets I give them a direction to go,
# In the parent node. Obviously you can change tha direction around if you want to.

func _physics_process(delta):
    if move_direction != Vector2(0,0):
    current_state =
match current_state:
        global_position += move_direction * speed
        global_rotation = move_direction.angle()
        pos = global_position
        global_position = pos

func _on_Area2D_area_entered(area):
#   if area.is_in_group("PlayerHitbox"):
#       area.get_parent().take_damage(dmg)
#       destroy_bullet()
if area.is_in_group("wall"):
    current_state = states.stop
by (137 points)
selected by

It worked just how I wanted, of course I'm gonna make the improvements I need.
Thank you very much, great answer, easy code after all :) Thank you

if the speed is too high, the arrow goes through the wall, some way to solve this?

You're welcome! :) I'm just trying to be a part of the community.

About the collisions not working, if the speed is too high: My only guess is that it goes so fast, that the game doesn't register that, the collision has been made. I didn't encounter such problem before, so I can't really think of anything else.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.