Hi!
Currently I'm trying to set up a gun that follows the mouse and shoots bullets (which are RigidBody2Ds).
I'm having a lot of trouble over it though, so a few questions:
1) What direction do nodes start facing? Is it a Vector2 of (0, -1) or would that be something you have to program yourself?
2) What's the best way to let the gun follow the mouse?
3) How can I add a child (the bullet) at the point of the gun, facing the same direction as the gun?
I'll link the entire project, it's a bit messy but hopefully it helps.
And for anyone who only wants the code:
The Gun:
extends Node2D
var mouse_pos
var bullet_scene = preload("res://bullet.tscn")
onready var bullet = bullet_scene.instance()
func _ready():
pass
func _physics_process(delta):
mouse_pos = get_local_mouse_position()
rotation += mouse_pos.angle() * 0.4
if Input.is_action_just_pressed("shoot"):
_shoot()
func _shoot():
get_node("BulletContainer").add_child(bullet)
bullet.position = get_node("GunTip").get_global_position()
print("shot")
Thanks so much in advance.