Godot Version
4.2.1
Question
So I’m making an ability system and currently working on the second ability although I am having some trouble with the ability objects global positioning. The ability system works by the player picking up an object that determines the players current ability. So i have created a general script that sets most of the rules for how the abilities should work and a another scene that the first script instantiates.
Ability1 script:
extends Player_State
@export var ground_state : Player_State
@export var Usable_ability_node : String = "Usable_ability"
@export var run_animation_node : String = "Run"
#-------------------------------------------
@onready var cooldown_timer: Timer = $Cooldow_ability1
#-------------------------------------------
# current ability
func on_enter():
var ability1 = character.current_ability1.instantiate()
cooldown_timer.set_wait_time(ability1.cooldown_time)
cooldown_timer.start()
character.add_sibling(ability1) # Adds to same parent as player
print("Ability added: ", ability1)
ability1.global_position = (character.global_position) + ability1.self_offset * character.latest_direction
print(character.global_position)
if character.latest_direction < 1:
ability1.scale.x = -1
else:
ability1.scale.x = 1
#-------------------------------------------
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
pass
#-------------------------------------------
func _on_animation_tree_animation_finished(anim_name):
if anim_name == Usable_ability_node:
playback.travel(run_animation_node)
next_state = ground_state
Air_blast script (the ability I’m working on):
extends Area2D
#Air blast script
#-------------------------------------------
@export var damage : int = 10
@export var Hit_effect_animation : String = "Hit_effect"
@export var self_offset = Vector2(0,-25)
#------------------------------------------
@onready var anim_player = $AnimationPlayer
#sets the wait time for the cooldown timer in the player scene
var cooldown_time: int = 3
var direction = null
#-------------------------------------------
func _ready():
direction = get_tree().get_first_node_in_group("Player_body").latest_direction
monitoring = false
if anim_player:
anim_player.play("Air_blast")
#-------------------------------------------
func _process(delta):
if anim_player.current_animation == "Air_blast":
self.global_position.x += (direction * 500 * delta)
#-------------------------------------------
func _on_body_entered(body):
for child in body.get_children():
if child is damageable:
child.hit(damage)
print_debug(body.name + " took " + str(damage))
anim_player.play("Hit_effect")
#-------------------------------------------
func _on_animation_player_animation_finished(anim_name):
if anim_name == Hit_effect_animation:
self.queue_free()
The Issue I’m having is that the abilities self_offset dosen’t get added to the global_position when the player is facing to the left for some reason. And I don’t know why
Any and all help is appreciated