Godot Version
4.3
Question:
I am newer to Godot, and I’m attempting to get a variable from my gun to my player, so I can have my player play a player animation that corresponds with where the gun is pointing. heres the code im working with for both my gun and my player. I did my best to try to find it out but I had no success
Player:
extends CharacterBody2D
>
>
> ## Movement-------------------------------------------------------------------
>
> ## variables for all movement
> const SPEED = 300.0
> const Dash = 500
>
> ## using this for where the gun is looking at
> const GunPosition = preload("res://Player/Weapon/gun.tscn")
>
> ## walking----------------------
>
>
> func get_input():
> var input_direction = Input.get_vector("left", "right", "up", "down")
> velocity = input_direction * SPEED
>
> func get_direction():
> rotation_degrees = wrap(GunPosition.rotation_degrees, 0, 360)
> if rotation_degrees > 90 and rotation_degrees < 270:
> ## i doubt this is the correct direction, this is here for testing purposes
> $AnimatedSprite2D.play("down-idle")
>
> func _physics_process(_delta):
> get_direction()
> get_input()
> move_and_slide()
###gun
> extends Node2D
>
> const Bullet = preload("res://Player/Weapon/Bullet.tscn")
>
> @onready var muzzle: Marker2D = $Marker2D
>
>
> func _process(_delta: float) -> void:
> rotation_degrees = wrap(rotation_degrees, 0, 360)
> look_at(get_global_mouse_position())
>
> if Input.is_action_just_pressed('Shoot'):
> var Bulletinst = Bullet.instantiate()
> get_tree().root.add_child(Bulletinst)
> Bulletinst.global_position = muzzle.global_position
> Bulletinst.rotation = rotation