Godot Version
v4.5.1
Question
my Combos dont work i have tried other ways too but it just dosent want to work
extends CharacterBody3D
const LERP_VALUE : float = 0.15
var snap_vector : Vector3 = Vector3.DOWN
var speed : float
@export_group("Movement variables")
@export var walk_speed : float = 1.5
@export var run_speed : float = 5.0
@export var crouch_speed : float =1.0
@export var jump_strength : float = 15.0
@export var jump_speed : float = 3.5
@export var gravity : float = 50.0
@export var roll_speed : float = 8.0
@export var roll_time : float = 0.6
@export var roll_coldown : float = 2.0
var combo = 0
var attack_cooldowns = [0.6, 1.6, 0.4] # cooldowns for attack1, attack2, attack3
var rolling : bool = false
var roll_timer : float = 0.0
var roll_cooldown_timer : float = 0.0
var roll_direction : Vector3 = Vector3.ZERO
var move_direction : Vector3 = Vector3.ZERO
@export_group("Attack")
@export var attack_coldown : float = 0.4
@export var attack_demage : float = 10.0
var attack : bool = false
var attack_timer : float = 0.0
var attack_coldown_timer : float = 0.0
var hit_enemies = []
var sword_timer : float = 0.0
var sword_show_timer : float = 0.2
const ANIMATION_BLEND : float = 10.0
@onready var player_mesh : Node3D = $Mesh
@onready var spring_arm_pivot : Node3D = $SpringArmPivot
@onready var animator : AnimationTree = $AnimationTree
@onready var collision_shape_3d: CollisionShape3D = $CollisionShape3D
@onready var short_sword: MeshInstance3D = $Mesh/Armature/GeneralSkeleton/BoneAttachment3D2/Warhammer_002
@onready var sword_collision: CollisionShape3D = $Mesh/Armature/GeneralSkeleton/BoneAttachment3D2/Warhammer_002/Area3D/CollisionShape3D2
@onready var hit_effect: GPUParticles3D = $GPUParticles3D
func _ready() -> void:
short_sword.visible = false
func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed("Exit"):
get_tree().quit()
func combo_timeout_timer():
combo = 0
func _physics_process(delta):
sword_collision.disabled = not attack
if attack_coldown_timer <= 0 and not attack:
combo = 0
if hit_effect:
hit_effect.global_transform.origin = short_sword.global_transform.origin
var just_landed := is_on_floor() and snap_vector == Vector3.ZERO
var is_jumping := is_on_floor() and Input.is_action_just_pressed("Jump") and not rolling and not attack
if is_jumping:
snap_vector = Vector3.ZERO
velocity.y = jump_strength
elif just_landed:
snap_vector = Vector3.DOWN
if sword_timer > 0:
sword_timer -= delta
if attack:
attack_timer -= delta
if attack_timer <= 0:
attack = false
hit_enemies.clear() # Done for this attack
attack_coldown_timer -= delta
roll_cooldown_timer -= delta
if Input.is_action_just_pressed("1"):
short_sword.visible = not short_sword.visible
if short_sword.visible:
sword_timer = sword_show_timer
if short_sword.visible and Input.is_action_just_pressed("Attack") and attack_coldown_timer <= 0:
combo += 1
if combo == 1:
animator.set("parameters/SABLEND/blend_amount", 0)
combo_timeout_timer()
if combo == 2:
animator.set("parameters/SABLEND/blend_amount", 1)
combo_timeout_timer()
if combo == 3:
animator.set("parameters/SABLEND/blend_amount", -1)
combo_timeout_timer()
animator.set("parameters/Attack/request", AnimationNodeOneShot.ONE_SHOT_REQUEST_FIRE)
move_direction.x = Input.get_action_strength("Right") - Input.get_action_strength("Left")
move_direction.z = Input.get_action_strength("Backward") - Input.get_action_strength("Forward")
move_direction = move_direction.rotated(Vector3.UP, spring_arm_pivot.rotation.y)
if Input.is_action_pressed("Run") and Input.is_action_just_pressed("Crouch") and roll_cooldown_timer <= 0 and is_on_floor():
if move_direction != Vector3.ZERO:
rolling = true
roll_timer = roll_time
roll_cooldown_timer = roll_coldown
roll_direction = move_direction.normalized()
velocity.y -= gravity * delta
if rolling:
collision_shape_3d.shape.height = 1.125
collision_shape_3d.position.y = 0.56
elif Input.is_action_pressed("Crouch") and not rolling:
collision_shape_3d.shape.height = 1.125
collision_shape_3d.position.y = 0.56
speed = crouch_speed
elif Input.is_action_pressed("Run"):
collision_shape_3d.shape.height = 1.85
collision_shape_3d.position.y = 0.92
speed = run_speed
else:
collision_shape_3d.shape.height = 1.85
collision_shape_3d.position.y = 0.92
speed = walk_speed
if rolling:
velocity.x = roll_direction.x * roll_speed
velocity.z = roll_direction.z * roll_speed
roll_timer -= delta
if roll_timer <= 0:
rolling = false
if not rolling:
if not is_on_floor():
velocity.x = move_direction.x * jump_speed
velocity.z = move_direction.z * jump_speed
else:
velocity.x = move_direction.x * speed
velocity.z = move_direction.z * speed
if rolling:
player_mesh.rotation.y = lerp_angle(player_mesh.rotation.y, atan2(roll_direction.x, roll_direction.z), LERP_VALUE)
elif move_direction:
player_mesh.rotation.y = lerp_angle(player_mesh.rotation.y, atan2(velocity.x, velocity.z), LERP_VALUE)
apply_floor_snap()
move_and_slide()
animate(delta)
func animate(delta):
if not is_on_floor() and not rolling:
animator.set("parameters/ground_air_transition/transition_request", "air")
return
if rolling:
animator.set("parameters/ground_air_transition/transition_request", "Roll")
return
if short_sword.visible == true and not rolling:
animator.set("parameters/ground_air_transition/transition_request", "Sword")
if velocity.length() > 0:
animator.set("parameters/swordBlend/blend_amount", lerp(animator.get("parameters/swordBlend/blend_amount"), 1.0 if speed == run_speed else 0.0, delta * ANIMATION_BLEND))
else:
animator.set("parameters/swordBlend/blend_amount", lerp(animator.get("parameters/swordBlend/blend_amount"), -1.0, delta * ANIMATION_BLEND))
return
if is_on_floor() and not rolling:
if Input.is_action_pressed("Crouch"):
animator.set("parameters/ground_air_transition/transition_request", "Crouched")
animator.set(
"parameters/Crouch/blend_amount",
lerp(
animator.get("parameters/Crouch/blend_amount"),
0.0 if velocity.length() > 0 else 1.0,
delta * ANIMATION_BLEND
)
)
else:
animator.set("parameters/ground_air_transition/transition_request", "grounded")
if velocity.length() > 0:
animator.set("parameters/iwr_blend/blend_amount", lerp(animator.get("parameters/iwr_blend/blend_amount"), 1.0 if speed == run_speed else 0.0, delta * ANIMATION_BLEND))
else:
animator.set("parameters/iwr_blend/blend_amount", lerp(animator.get("parameters/iwr_blend/blend_amount"), -1.0, delta * ANIMATION_BLEND))
func _on_area_3d_body_entered(body: Node3D) -> void:
if attack and body.is_in_group("Enemy") and not body in hit_enemies:
hit_enemies.append(body)
attack_enemy(body)
func attack_enemy(enemy: Node) -> void:
# Check if the enemy has a health property
if enemy.has_method("take_damage"):
if enemy.health > 0:
hit_effect.emitting = true
enemy.take_damage(attack_demage, global_transform.origin)
print("Attacked enemy! Remaining health:", enemy.health)
# Optional: play attack animation or sound