Need help moving player.

0ven

  • Posts: 19
I'm trying to make melee combat and am having some trouble keeping the player from moving while he is attacking.

So in this picture the program checks if a mouse button is pressed and if one is then it checks to see if the "swing" attribute is set (Swing attribute is set if the player is already attacking), if it is not then the players x and y coordinates are stored into attributes and the attacking animation begins. After the animation ends it returns to its original animation.

In this picture if the player has collided with a actor and the mouse was pressed after the attack animation is over (SwordAnimeTime is how long the animation takes) the actor that he collided with will be dealt 1 damage.

Lastly in this picture is what isn't working properly, the game checks to see if the player is doing his attack and if he is then it should move him to where he had began the attack. Although it doesn't...

If anyone knows why it doesn't work or knows a better way to implement this system I'd really appreciate the answer, thanks.

rahulmartin

  • Posts: 315
how'd you set your swordAnimetime ? im in some same sort of situation where i need this clause of do after ___ seconds.

0ven

  • Posts: 19
how'd you set your swordAnimetime ? im in some same sort of situation where i need this clause of do after ___ seconds.
For swordAnimetime I just multiplied the amount of frames that I had by 0.1 since each frame lasted 100ms and used that. For now it's manually entered and I would have it so if the player gets another weapon or something then his swordAnimetime will change to however long the new weapons animation would take but there probably is a way to figure out the amount of frames that are being used and use that, that might be more efficient. Although since I'm new to this I'm just keeping it simple for now.

Still looking for an answer to the above question btw.

Sauvus

  • Posts: 1
Bump. Looking for answer.

rahulmartin

  • Posts: 315
Maybe the last clause isnt executing at all because before it executes may be the attribute swing becomes false.

use this :
 make another click event [when the mouse is released]
set swing = false;
switch animation to animation 3;


you can also try moving the update event up in the priority (the little up arrow button). ;)

-give it a try, you helped me a lot with the post .thnx.   ;D


Sift

  • Posts: 47
I think it might be because of the push towards Xdir and Ydir part. When you have the X of the character and Y of the character in place of those it most likely does not push it towards the original position during the click. However, it is most likely that a force is acting upon the actor(probably pushing it downwards on a tile which is why it doesn't move) . I'm not so good at math, but there's probably an equation to push your character towards that original position. Or if you feel up to it you could use the "Slide to X, Y" Block, but it does not detect collision according to my knowledge.