Attack lunge movement help

Godot Version

4.6.3

Question

This has probably been asked before but is there a way to do a smooth attack lunging movement that can be tied to the characters attack animation?

i’ve tried tweens but they ignore collisions until finished; messed with move_and_collide but it was a bit too instant for me but had the closest result to I want.

is there another way or do I just have to use move_and_collide?

I haven’t coded anything like this yet but maybe you could get the distance to the target and break it done into multiple steps. For instance cover the first 20% and then finish the first move. I’m not sure how that would work with tweens but something like that could be used to slow the move and collide.

For the player, I just want them to move a little bit forward when attacking. Similar to Dark Souls/Elden ring when the character attacks the step forward but for 2d.

Although, when I get to making the enemy, that may work.

What stops you from just using move_and_slide()?

i am using move and slide

just want the attack to move a little bit forward a set distance in a non-linear fashion. then add it to the animation in the call function track

I.e. not gliding across the floor

I already stopped movement for the attacks

Just use move_and_slide() and accelerate a bit. When you’re done, tween the position back to initial position.

wouldn’t the tween not apply collisions after its done?

What do you mean by “apply collisions”?

Wouldn’t there be the potential for overshooting or going through an intervening object though? I haven’t looked at tweens myself but I would assume that those issues would be fixable in some way.

When I tried tweens, the player went into the wall; then when the tween was done; shot to the top of the wall collision.

In better words, do tweens ignore all collisions until its done?

That’s why you go forward using move_and_slide() and only return using a tween. You know that the position the player is returning to is reachable because they stood there a moment ago.

is there a unique thing I can do with move_and_slide besides what I already have in the phys process?

func _physics_process(delta: float) -> void:
	state_machine.update_physics(delta)
	input.update_input()
	flip_sprite()
	update_collisions() # Change collisions from standing to crouch and vice versa

	move_and_slide()

Well you can animate the velocity if you want non-linear motion.

To Lunge during an attack, what you want to do is apply velocity to the character in the Lunge direction, then turn down the velocity to zero over time. I’ll write a 2d example.

When the attack starts, you apply velocity in the forward direction like this:

velocity.x = 1000.0
move_and_slide()

This piece of code applies a constant velocity to the player, moving them to the right. Depending on what you need, you can slowly turn down that velocity, or hard stop it.

If you want to slowly turn it down, you can do something like this:
velocity.x = move_toward(velocity.x, 0.0, 0.1)
move_and_slide()

This slowly reduces the x velocity of the player until it reaches zero. If you want a faster stop, just increase the delta value. *(You can also use lerp instead of move_towards, although I read it’s not as accurate)

If you want a hard stop once the animation is done, just set the velocity.x to 0.0*

That’s it! You’ve successfully applied a lunge during your attack.

Now, tying this into your animation system depends on how you setup your animation. You might need to setup a timer for this so your game know how long the lunge should be for and when to stop lunging.

I just settled on move_and_collide because the velocity did slow down enough thanks for the suggestions though.

func attack_lunge(amount : float):
	move_and_collide(Vector2(amount, 0) * input.last_direction )