Little problem in my movement events [Resolved]

0 favourites
  • 4 posts
From the Asset Store
14 amazing sound files of game events like Level Ups, Level Completes, object spawn, object taking etc.
  • Foreword: I noticed, after I was done typing, that this turned into something of a dissertation. Apologies beforehand for the wall of text.

    Hello, all. I have some experience with various other game-making software, but I'm completely new to Consturct 2, so I decided that this might be the best forum for my question. I started throwing together a simple top-down-shooter the other day, and I'm having a little issue in my movement sequence.

    The "player" consists of two sprites: Player, and Player_Feet. The Player sprite is the body/arms/gun/etc., and the Player_Feet sprite, as the name might imply, is just movement animations for the legs and feet. I separate the two because I'd like them to move independently of one another. The player rotates to face the mouse, and WSAD is used for 8-direction movement.

    What I'm trying to achieve is an effect that I've done before in other engines: since the player always faces the mouse, but has free range of movement, I want the animation for the feet to switch between back-and-forth and strafing left/strafing right based on his movement and relative angle to the mouse. (It looks bad, to me, to have the legs swinging back and forth when the player is obviously moving side-to-side.)

    What I have thus far works just fine, except during diagonal movement. Whenever multiple movement keys are pressed at once, the leg animation "sticks" on the first frame, and does not animate. My previous programming experience is telling me that my problem is likely that I have one or more of the conditions in my event sequence firing repeatedly, and it's setting the animation back to the start while the buttons are held down, giving the illusion that the sprite isn't animated. But, I'm either too tired, or too nearsighted to find the error.

    Below is posted an image of the event sequence that I'm using for movement. I also have the .capx file up in my Google Drive, and I can provide a download link to that if necessary.

    As an aside: Like I said, I'm new to Construct 2 and it's way of doing things. If anyone has any advice for optimizing or compacting my event structure, I'd be delighted to hear it.

  • First to address refactoring and compacting your event structure, my advice is to not worry about it at all unless it becomes a problem and you have performance issues! I know how satisfying it can be to go over your code and make everything more compact and efficient, but often the way you first imagined the logic to work out in your head is how you set it up in the first place, and that will be the easiest to understand and read for you later, while extremely compact code might be difficult to decipher later down the road when you have a lot more to think about.

    That said, the simplest solution is often the best solution, so sometimes if you find your code getting too complicated, it might be a good idea to step back and see where things could be simplified.

    In this case, given that your movement is working properly with each direction and diagonals, I would separate the feet animation code from the keyboard input code. Use a variable to keep track of which direction they are going (1-8) and play the correct animation based on that variable.

    You might be able to save some animation frames by using the "Mirror" action too, but that can introduce some new complications as well so I would leave that for after you get it working the way you want first.

  • I remember doing something like this before where I compared the mouse controlled player sprite angle with the 8dir moving angle to see if it's moving sideways or not.

    Here it is:

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thank you both for the help and feedback. ramones, your movement detection solution functions perfectly, and is significantly easier than the methods I was using. Since I'm new to the engine, I didn't even know those methods existed.

    Not only does my movement system now work as intended, but I was able to shave nineteen events off of my event sheet. Again, thanks for the hand.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)