- Edited
Hi!
I'm trying to make a mount&blade style 4-directional combat system and I got most of it working. A feature of the combat is that the player can chain attacks if he presses attack while already attacking. The problem Im having is that this chain function is working when I chain attacks in different directions each time, but not when I want to chain attacks in the same direction. So basically I want to be able to attack in this order: AttackLeft->AttackLeft...
whereas right now it goes like: AttackLeft->Idle->AttackLeft
If I'm Attacking in one direction, and I press attack in that direction again, I want the animation to smoothly transition back to the beginning of that animation, instead of going to the Idle Animation first and then going to the attack animation. I'm sorry if I'm not being clear enough. Here's a video where I try to explain it better(sry for the quality):
Video
This is the image for the State Machine that controls the attack animations:
I know its a mess lol.
@export var animTree:AnimationTree
var attack_pressed: bool
var attacking: bool
var attack_dir: String
var attackTransition: String
func _input(event):
### This is where I determine the attacking direction based on mouse-movement.
if attack_pressed:
if (event is InputEventMouseMotion):
if event.relative.x >= 2 and event.relative.y > -2 and event.relative.y < 2:
attack_dir = "Right"
elif event.relative.x < -2 and event.relative.y > -2 and event.relative.y < 2:
attack_dir = "Left"
elif event.relative.y <= -2 and event.relative.x >= -2 and event.relative.x <= 2:
attack_dir = "Up"
elif event.relative.y > 2 and event.relative.x >= -2 and event.relative.x <= 2:
attack_dir = "Down"
else:
attack_dir = ""
else:
attack_dir = ""
func _physics_process(delta):
if Input.is_action_just_pressed("Attack"):
attack_pressed = true
elif (Input.is_action_just_released("Attack") and !attacking) or (attack_dir != "" and attacking):
attack_pressed = false
if attack_pressed and attack_dir != "":
attackTransition = "parameters/OneHandedAttackTransition/transition_request"
animTree.set(attackTransition, "Attacking")
print("3")
var playback = animTree.get("parameters/OneHandedAttacking/playback") as AnimationNodeStateMachinePlayback
playback.travel("Attack"+str(attack_dir), false)
/// These two functions are called as methods within the attack animations
func attack_begin():
attacking = true
func attack_end():
attacking = false```
(I dont know why this part is getting put into my code. Its supposed to be part of the post.)
Again, really sorry for the mess, I'm not the best programmer. I realize this might be a lot and am not expecting someone else to do the whole thing for me. I'm just stuck with this small detail of my combat system and I'm appreciative of any help I can get.