0 Favourites

How do I create advanced controls+animations?

  • Ok, here's the deal:

    So we've got the main idea of the game we want to create.

    Now i've started to work on the very basics, to see if the gameplay will be actually possible. And if it's going to be fun that way.

    Our most desire: great controls.

    without that, any game is going to be... yea you know.

    Please note:

    The camera Angle is ISOMETRIC (diablo style)

    Controls:

    8-way Movement with keyboard.

    I've tested this one already, and i was able to create a great animation using Diablo Character Sheets (just for testing of course) based on the direction the character is walking to.

    Now, i want to improve the controls and go a step further.

    I'm looking for a 8-way movement with keyboard.

    BUT rather than the character is looking in the direction indicated by the keyboard walking.

    The character shall always look into direction of the mouse cursor!

    So you can AIM (for shooting / hitting) with the mouse.

    However things will get more complicated ones the character animation shall go backwards, if you're aiming into the other direction than you're walking to. (shooting while walking backwards for example)

    I guess it will require quite a few events.

    I wasn't able to find any tutorial for this kind of controls, and we would be happy to get some support from you guys.

    Also on a sidenote:

    The game shall also support multiplayer (at least 4 players)

    Thanks in advance for your support!

  • I just got Construct 2 and am planning to make a bullet-hell kind of shooter as my first experimental project (something along the lines of Realm of the Mad God). I'm also trying to figure out how to implement this type of player movement but at the moment I'm totally stumped!

    I've tried a few tutorials on Direction-Based Sprite Movement and Aiming and Moving Independently, and was able to get a character to move and fire in separate directions; however, I have yet to figure out how to get the character to stay facing the mouse cursor while moving backwards, for example. Anyone care to share any nuggets of wisdom?

  • You can use a condition that says "if mouse is top right of player, player looks top right" by using the Mouse.X and Mouse.Y to pinpoint where the mouse actually is.

    When using the 8 movement directional behavior you can "Set Angle" to "No" at the left of your screen so the angle doesn't change when moving.

    I hope this helped you a little in the direction you want to go

  • You got stuck with the exact same issue like me ^^

    By the way:

    I've got the multiplayer part managed.

    The biggest issue i'm facing is still the movement / aiming / animation combination as Vespyr has described above.

  • rezagamertag:

    That does not help in this case i think.

    The angle is set to no, i can move just fine without the sprite to rotate.

    As i've said, i'm talking about an isometric game style.

    So the ANIMATION should change depending on:

    Direction the Cursor is pointing, compared to your player position

    while

    Additionaly run animation backwards depending on player movement

    I think my description just gave me an idea how to be able to do it.

    I'm gonna try it tomorrow ^^

    However support is still welcome.

  • Which gives you 2 conditions to meet:

    • Are you moving backwards?
    • What direction is the mouse pointing?

    For both you will have seperate events like for example

    If moving backwards & mouse is top right: do this

    If not moving backwards & mouse is top right: do this

    If moving backwards & mouse is top left: do this

    And so forth.

    That's my 2 cents

  • With 360 cursor aiming (cursor)

    With 360 player movement (keyboard)

    There is no possibility to simply set "If moving backwards" <----- That's the issue we're having here!

    We need something like "If player is moving away from cursor position = set animation reverse"

    + Set Animation Right If cursor position is >29 & < 31 degrees from player location

    + Set Animation DownRight If cursor position is >30 & <61 degrees from player location

    + Set Animation Down If cursor position is >60 & <100 degrees from player location

    etc......

    Set STANCE animation as well if not walking, so another 8 different animatons

    So there's quite a few things we have to do here!!

    Not just 2 simple checks....

    There's not simply ONE backwards walking. It's 360 degrees possible to walk either back or forth.

    (Back and forth can be triggered by reversing the animation i guess.)

    So 8 different walking animations looking into 8 different directions:

    Up

    Down

    Left

    Right

    UpRight

    UpLeft

    DownRight

    DownLeft

    Vespyr's issue might be possible with just an upright check.

    But not what i'm willing to do.

    Here a complete character sheet i will require for walking into all directions:

  • This might simplify things a bit.

    Rename the animations to Angle1,...,Angle8 based on:

    Angle1 = 0 to 45 degrees

    Angle2 = 46 to 90 degrees

    Angle3 = 91 to 135 degrees

    Angle4 = 136 to 180 degrees

    Angle5 = 181 to 225 degrees

    Angle6 = 226 to 270 degrees

    Angle7 = 271 to 315 degrees

    Angle8 = 316 to 359 degrees

    Then set the animation based on the angle between the player and the mouse:

    System->Set aim_angle to angle(Player.X,Player.Y,Mouse.X,Mouse.Y)
    
    System->Set aim_angle to aim_angle < 0 ? aim_angle + 360 : aim_angle
    
    Player->Set animation "Angle" & 1 + floor(aim_angle/45)[/code:20yc7kaj]
    
    This way they should look in the right direction and to get them to appear to be walking backwards check the difference between the player angle and aim_angle and if it is great enough put the animation in reverse.
    
    The easy way to get the player angle is to leave the 8 Direction Set Angle property at 360 Degrees (smooth). Only problem with this is it rotates your character, so you need to set the Player.Angle to 0 after you do your checks every tick.
    
    [code:20yc7kaj]System->abs(Player.Angle - aim_angle) > 90
       Player->Set animation speed = -1 * Player.AnimationSpeed
    Else
       Player->Set animation speed = abs(Player.AnimationSpeed)
    
    Player->Set angle to 0[/code:20yc7kaj]
  • [quote:tdyt0neb]The easy way to get the player angle is to leave the 8 Direction Set Angle property at 360 Degrees (smooth). Only problem with this is it rotates your character, so you need to set the Player.Angle to 0 after you do your checks every tick.

    I know what you mean, i've handled this issue already before by simply adding the actual animation sprite on top of the player itself.

    So the player is set to invisible.

    And rather than pinning the animation sprite to the player, i have set it's position to player every tick.

    i'm just not sure if that's such a good idea as in performance perspective.

    But thanks a lot for your help!

    Going to test everything now.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Thanks a lot!

    This little piece already did the trick to be able to change the animation based on cursor location.

    I will just have to work this whole thing out now.

    I will try to add animation upon walking now and finish the whole basic movements.

  • Wow, thanks so much for the help, OddConfection! I tried changing sprite animations based on mouse/player angle relation as you suggested and it works like a charm.

    Quick newbie question, though: in your event code example, is aim_angle referring to an instance variable? At the moment I have my sprite changing animation based on a simple though possibly inefficient use of System > Is Between Values > angle(Player.X,Player.Y,Mouse.X,Mouse.Y) and setting the angles as the upper and lower bounds (repeated 4 times for 4-directional movement in my case). Your method seems to be doing just that but in fewer events. I guess I need to get used to reading event shorthand as I'm still pretty much a newb...

    Thank you again for the help! And good luck to Everade on his project. :D

  • I know what you mean, i've handled this issue already before by simply adding the actual animation sprite on top of the player itself.

    So the player is set to invisible.

    And rather than pinning the animation sprite to the player, i have set it's position to player every tick.

    i'm just not sure if that's such a good idea as in performance perspective.

    But thanks a lot for your help!

    You're welcome

    Pinning and setting the position every tick are pretty much equivalent, just one is handled by events and one by behaviour, but there shouldn't be any performance issues.

    Using an invisible player sprite is often recommended e.g. for use with the Platform behaviour for colliding with platforms, the only issue I can think of with that using 8 Direction movement is the invisible object is rotating and so is it's collision box which might cause the player to get stuck on things.

    @Vespyr

    You're welcome too I'm glad the method worked for you as well

    In the code I posted, aim_angle is a Global variable but you could use an instance variable e.g. Player.aim_angle, which might be useful in a multiplayer game instead of having global variables for each player.

    Good luck to you both with your games.

  • Currently the game looks like shown at the bottom.

    As you can see, the "Peer" (star) is set to invisible.

    Peer angle always looks into cursor direction, and bullets are spawned on Peer angle so they fly into the direction you're aiming.

    The Character Sprite "animated" is simply set to position "Peer" every tick.

    They look into the direction the cursor is aiming as shown in the Events at the top.

  • I really need some help.

    I was brainstorming like hell and cleaned up the whole events, in my point of view my solution should be really simple with just these few events.

    As you can see in the picture here, i have cleaned up the events to display my character animation.

    Everything works as expected.

    Unless the Event at the very bottom.

    "If Moving, Start Animation"

    Could someone tell me what's wrong about it?

    I really can't tell...

  • Is there anyone who could help me with my last post above?

    I really can't figure out why the animation does not start to move.

    I've also replaced "system repeat 1 times" with "system trigger ones while true"

    Still, the animation never starts at all.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
167 39,769
lucasgc1's avatar
lucasgc1
Unread hot topic
99 10,136
karshinkoff's avatar
karshinkoff
Unread hot topic
56 4,728
MPPlantOfficial's avatar
MPPlantOfficial