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.
Jorge | 2020-06-24 17:15
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
BrunoFreezee | 2020-06-24 17:17
it is fine to share links, however, I had already seen, it does not help much
BrunoFreezee | 2020-06-24 17:19
For stuff that needs to move, yet also needs to interact with the surrounding collisions, I use a KinematicBody2D.
Hello!
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):
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
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
BrunoFreezee | 2020-06-24 21:10
if the speed is too high, the arrow goes through the wall, some way to solve this?
BrunoFreezee | 2020-06-24 21:36
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.