ID:265028
 
Problem description: I've been working on a New Sidescroller Game using ForumAccount's Library, it works perfectly, but I have a small problem which is annoying the players. When you click left or right button, the character can moves, when you hold x and you click left or right button, your character runs. Well, when you're pressing the keys (even though you've stopped pressing them after executing the attack) you continue moving to the place you were facing after being unfrozen (It freezes you for a bit when attacking, so you can't move when your character icon state is "attack"). The same happens to all the skills I've added, after executing them you continue walking, and stop walking / running to that place, you have to click left (if you were walking to the right, or right, if left...) I can't reveal any code, because I don't know what's wrong.

I wish ForumAccount could explain me something about this, or somebody's who already working on a Sidescroller game, thank you so much, and sorry for posting such a confusing thread.

Thanks!


Without seeing the code I can't tell what the problem is. How do you handle the freezing and unfreezing of movement after the player attacks?

I'd do something like this:

mob
var
attack_cooldown = 0

action()

// if you've attacked recently, decrement the
// counter and do nothing else.
if(attack_cooldown > 0)
attack_cooldown -= 1
return

// the Z key makes you attack
if(keys["z"])
attack_cooldown = 10
vel_x = 0
flick("attack", src)
return

// the X key makes you run
if(keys["x"])
move_speed = 8
else
move_speed = 5

..()
In response to Forum_account (#1)
Thank you so much for your help, @Forum_account.

I've successfully fixed the bug changing the stop proc (:

<code>stop() world<<"test" // this was just to check if the proc was called O.o keys[controls.left] = 0 // this is what stop the movement to left (: keys[controls.right] = 0 // this is what stop the movement to right (: holding_right = 0 // this isn't needed, I believe. holding_left = 0 // this isn't needed, I believe. destination = null next_step = null path = null __stuck_counter = 0</code>

Everytime an attack / skill is executed, stop proc is called, so it can stop the mob from moving (: I thought I'd have to live with this problem forever, but now it's fixed I feel really happy ^^
In response to Eternal_Memories (#2)
Glad to hear it was fixed.

After posting I thought of another way you might be able to fix it. To prevent the mob from moving, set their move_speed = 0 when they attack (and restore it later). The slow_down() proc makes you stop moving when you release a key and it makes players slow down if they're moving faster than their move_speed. You want players to slow down after attacking even if they continue pressing the arrow keys, so setting their move_speed to zero will do the trick:

mob
var
attack_cooldown = 0

action()

// the Z key makes you attack
if(keys["z"])
attack_cooldown = 10
move_speed = 0
flick("attack", src)

if(attack_cooldown <= 0)
// the X key makes you run
if(keys["x"])
move_speed = 8
else
move_speed = 5
else
attack_cooldown -= 1

..()