I am making a bullet-hell game and new to Godot and the forum. I had a problem where the player sprite would rotate relative to the cursor position which made moving awkward, so I made a "gun" Area 2D node that rotates instead of the sprite. However, when I run the game, the gun's origin seems to spawn on the bottom right. I think it may have something to do with get_local_mouse_position() or get_global_mouse position ()? Here is the code:
THE GUN
extends Area2D
var bullet_scene = preload("res://Scenes/Bullet.tscn") ##is the bullet "scene" (object)
func get_input():
if Input.is_action_pressed("ui_mouse_left"):
Fire()
func _physics_process(delta):
get_input()
look_at(get_global_mouse_position())
func Fire():
var BULLET = bullet_scene.instance()
BULLET.position = get_global_position()
get_parent().add_child(BULLET)
THE BULLET
extends Area2D
var BULLET_SPEED = 6
var BULLET_POS = Vector2()
onready var CURSOR_POS = null
func _ready():
CURSOR_POS = get_local_mouse_position()
func _process(_delta):
BULLET_POS = BULLET_POS.move_toward(CURSOR_POS,_delta)
BULLET_POS = BULLET_POS.normalized()*BULLET_SPEED
position = position + BULLET_POS