Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Root Animations & Physical Movement

Discussion in 'Game Design' started by xCeas, May 20, 2020.

  1. xCeas

    xCeas

    Joined:
    Mar 31, 2013
    Posts:
    50
    Hello all,

    I am working on a networked game where the movement is controlled by the code (the server gets the final word on a character's position).

    I have root animations which I'd like to blend with the physical movement done through the code.
    The animations that seem most problematic to me are those that are reactionary, for example a "throw object" animation, which has multiple vectors of movement throughout the animation.

    Does someone have any experience with that and wouldn't mind sharing it?

    I've thought of using a Queue to store which vectors should be applied at each step, however since these vectors directly control the animation's fluidity it would probably look bad especially with lags
     
  2. bigRUSH

    bigRUSH

    Joined:
    Jul 19, 2019
    Posts:
    19
    We also have networked game with different skills that have their own animations. So the idea to run animation only on client and sync with server only the result. For example if you want to release fire wave from object, You will run fire wave animation only on client, but server will receive position where fire wave started and final destination (also can be more data: duration, damage, etc...). Im not expert, but this is how we solved such issues.
     
  3. xCeas

    xCeas

    Joined:
    Mar 31, 2013
    Posts:
    50
    Thanks for the reply!

    In my game I don't use unity's networking solutions to sync players, but implement it by myself.
    How did you manage to sync client-side prediction with the root animations?
    To be more specific.
    Say I have 2 player objects (1 remote, 1 local) both have root animation toggled on
    Player 1 casts a skill which will cause player2 to be lift (or some other complex physics that isn't related to that player's input movement).

    With your solution did you lock movement input from the player that was struck - for the duration of the animation?

    Also how do you sync the root motion movement (regular walk/run/etc) along with the server's decision on the player's position.

    Thanks again
     
  4. bigRUSH

    bigRUSH

    Joined:
    Jul 19, 2019
    Posts:
    19
    @xCeas we are also not using unity build in mechanism for managing networking. Instead we are using PUN 2 and for now we using a user as a host for other players, but this is temporary, soon we will use real server.
    We not locking any objects during movements or animations (maybe skill itself can lock player, but this is skill script logic, we have block hole skill that block user from using skills and their movements disable, black hole itself move network objects and network objects that can be effected have property array of effects that have affect on object: slow, burn, disabled movement, disabled skills, etc... so same object can be slowed and burn with disabled movement at once), we update it with PUN (I believe its some kind of open socket than never closing during session).
    Example of moving:
    - User 'A' is moving in some direction:
    1. On 'A' user we run local animation of move from x1 y1 to x2 y2 (coordinates will be posted to PUN server).
    2. Other users connected to same PUN session and they subscribed on sessions updates.
    3. Other users receives signal that user 'A' moved from direction x1 y1 to x2 y2 so they run same move animation only on client for them.
    Same for skills with animations.
    Since skills animation is separated system from movement in our system we can run skills and update them separately.
    With such implementation sometimes you can have network glitches and de-sync of network objects, but there are work around. PUN and Valve have a lot of topics about lag compensation and predictions, there maybe few options that you need to implement (depends on your needs) to have smooth movement and animations.
    But still even some cool games like CS or Dota have glitches especially when clients have internet connection issues (high ping), You can see it when on your client your character have run animation but its not moving or your character teleporting to position where he was few sec ago. This because run animation was done on your local machine but since you have issues with server connection, you are not receiving any updates and server not register your movement.
     
    Last edited: May 20, 2020
  5. bigRUSH

    bigRUSH

    Joined:
    Jul 19, 2019
    Posts:
    19
    @xCeas so example with lift skill animation:
    1. Player 'A' use lift skill on player 'B'.
    2. Since players are connected to same session player 'A' send data to that session that he used skill lift on player 'B'.
    3. Server can check all data and send clients some data message: { user: 'a' skill: 'lift' target:'b' duration:'2' damage:10 allow: true }
    4. After your clients receiving this message run animations on their machines locally.
     
  6. xCeas

    xCeas

    Joined:
    Mar 31, 2013
    Posts:
    50
    @bigRUSH I am not familiar with PUN I will check it out.
    So in your movement logic does the root motion animation control the delta between an object positions?

    And regarding the skill example,
    if the "lift" animation controls the affected object's movement, then I assume the following are correct:
    - that object can not apply input during the animation (it is possible to queue his inputs but not play them since he is mid-animation)
    - the server should be aware of the movement which leads back to your first reply, if you'd send only the start and end positions and the player could be attacked/collided mid animation that means that the server does not know where that object precisely is and therefore it can not apply inputs which might affect it (I guess it can be "mitigated" by lerping between the start and end position.

    I should also note that my game is a co-op and it will server 4 players max, and I've decided to have the server inside the host's machine (unity runs the server too)
     
  7. bigRUSH

    bigRUSH

    Joined:
    Jul 19, 2019
    Posts:
    19
    @xCeas
    1. No queue of events, is something happening it happens now, maybe some script can delay actions but again its related to script logic. PUN for example can call update function 24 times per seconds. So if your character casts 'Lift' skill or under 'Lift' skill in same time it can move or cast another skill (of course if 'Lift' script do not block that logic), you just need to update server about new events.
    2. If object attacked or collided you should update server with that specific event(s), you shouldn't wait until some action will be finished. Take for example MOBA game: you character at position x1 y1, and you clicked on position x2 y2 and your character now move to position x2 y2, but in some moment you decided to change final destination to x3 y3 when your character wasn't on x2 y2. What this mean? You update server with new final coordinate x3 y3 and on client you changing just position where character should move without even stoping move animation. If during moving from x1 y1 to x2 y2, somebody attack character, attacking character publish new event to session that he made attack, server register this event and if attack indeed hits character server also register that event and for example register some damage, but move from x1 y1 to x2 y2 not stopping unless that attack won't block character movement or character itself don't stop moving or changed final destination.

    P.S. Don't try to implement networking by yourself, better use already existed solution like PUN or build-in unity. This is pretty complex technology you will just waist a lot of time by your own implementation.

    P.S.S my game is online arena 3 vs 3 characters MOBA like.
     
  8. xCeas

    xCeas

    Joined:
    Mar 31, 2013
    Posts:
    50
    1. I meant a queue of inputs similar to the Dark Souls input system your inputs are queued so if you "panic" clicked on an input you will "pay" for it - but this is more of a gamey feature
    2. I completely agree on this point and I've already implemented movement with client-side prediction (and you can stop moving in a direction and go somewhere else if you like). Though what I've meant is that, if you for example are affected by "lift" animation that means you as someone who is currently playing this disrupting animation should not be able to send movement inputs.

    Your game looks really cool, do you have a thread where you update about it?

    And for the note about the networking, I'm implementing the networking layer on purpose so that I can learn and understand those layers better.
     
  9. bigRUSH

    bigRUSH

    Joined:
    Jul 19, 2019
    Posts:
    19
    @xCeas this thread became our small chat :)
    1. Sure you can do some kind of lock for every action, and even queue them, but soon as you do it on client send it to server for registration. I think this is more gameplay feature than networking.
    User making some action -> send to server -> register action allow/not allow it -> send response to clients -> run that action animation on client side if action was allowed.
    Allow/not allow - this is more for checking if user not cheating by manipulate your request data.
    2. Sure you can change network object properties (like speed, rotation, so on). As I mention earlier, your network object (player for example) can have property of array type we can call it 'effects'. For example skill 'Lift' will trigger new event that will add new object to that 'effects' array, let's name it 'immobilize'. Object 'immobilize' can have some params 'duration', 'animation', etc.. So if your player will have this 'immobilize' in it's 'effects' array you can disable movement for duration of 'immobilize' effect, so you will stop send movements events to server and even if somehow user can break it check on server what current effects have your player, and if its 'immobilize' don't allow to move. By having array of 'effects' you can add as many effects as you wish in same time.

    In two weeks I will prepare working demo in Feedback Friday thread (currently working on web client, mobile almost ready).

    Unless you don't want to be networking guru, its ok is just to understand networking ;) Networking is very huge by itself with a lot of different protocols, socket managing, etc... :)
     
    xCeas likes this.
  10. xCeas

    xCeas

    Joined:
    Mar 31, 2013
    Posts:
    50
    @bigRUSH I'm enjoying this chat :)
    1. For any network model to be reliable there must be some sort of locking or caching data between game ticks (even if it is done at the lowest level of the API you are using), imagine a scenario where a player connects to a game and a mil second before he was in, there was a command that altered the state and he might miss it due to "bad" timing. In the context that we were discussing we referred to both (probably because I wasn't clear enough at the beginning so sorry about that), and the model that you described is exactly what I'm currently using.
    2. That sounds reasonable, I guess that it is possible to handle the root motion flow of the "lift" skill a bit different (please let me know what do you think about the flow below).

    1. *Client: Player casts "lift" --> play "lift" animation (without raising enemy collided objects) + send "lift" cast packet
    2. Server: Receives "lift" packet --> verify (let's assume approval) + apply "lift" effect (there can be multiple ways to calculate who will be affected: either receive it from the client and verify to some extent, try to predict using pre-known timings and positions, animation events/effect events will communicate to the server directly)
    3. Server send "lift" result packet --> depending on the apply flow this packet will differ (regarding the point above I'm not sure whether or not acknowledging client decisions will be the best way to handle the effect result)
    4. All Clients: receive "lift" result packet --> caster will play "lift" animation, and again depending on how the "lift", apply the "lift" damage, effect etc on hit characters + hit objects should play the "lifted"* animation

    Notes:
    1* to synchronize the player's movement with the lift animation I might be able to use unity
    Code (CSharp):
    1. OnAnimationMove
    method, instead of the Input.getAxis
    2* I think that synchronizing "lifted" objects could prove to be harder.
    If I assume the server is running inside the host's engine, I can assume that all bots are controlled via the host and therefore I can apply the "lifted" animation on the client though the movement will be controlled by the server

    "In two weeks I will prepare working demo in Feedback Friday thread (currently working on web client, mobile almost ready)"
    I'm glad to hear that I'd love to see the demo.

    And I do indeed wish to become a networking guru, I've began this project with the intent of learning :) (A last side note: I do not implement the sockets layer only how it is used)
     
    bigRUSH likes this.
  11. bigRUSH

    bigRUSH

    Joined:
    Jul 19, 2019
    Posts:
    19
    @xCeas I like to speak about networking in general, I started my first game ever and its with networking, so i'm not so expert here, but I had a lot of projects (not games) with VOIP (video, voice) chats, text chats on sockets :).
    Your flow seems OK. But still this is pretty low level networking. 'Bad' timings and sync issue corrections, already build in PUN framework or any other third part library. The idea is to subclass network object from PUN class and instead unity instantiate method use PUN instantiate method, so you don't need to use something like 'OnAnimationMove' to sync. PUN will do a lot of work by himself. Also if you try to make your networking solution, keep in mind that if your game will run somewhere on remote server you should have some CDNs to avoid large delays (I think best is to use some service as AWS).

    I still recommend you to use some third party service for networking :) Because if you decide to use it when there will be a lot of classes and scripts, you will need a lot of time to subclass them all from networking objects and change the way of instantiation + some other small things.

    BTW for bots you are using FSM?
     
  12. xCeas

    xCeas

    Joined:
    Mar 31, 2013
    Posts:
    50
    Thanks for reviewing the flow, I'm trying to implement as we speak (basically shaping the existing code to match this pattern), I'm not sure I understood your point when you recommended me to use 3rd party networking solutions. Since I create a LL solution (no "fancy" API that can be used in many ways) I receive a custom solution for my needs, for better and worse - I am doing it mainly so that I could improve, for most times it is very enjoyable (to me it feels like defeating a boss in Dark Souls).
    In my case CDNs wouldn't be necessary since the game will be hosted on a client (similar to how 2000s networked games worked (Diablo2, Heroes of M&M)

    For the AI I actually have multiple brains implemented differently (currently using 1 brain but I will eventually use all of then).
    The brains I have are as follows:
    - NPC daily schedule - GOAP (not 100% GOAP but very similar, I have actions which I give them a base score, and through context change I apply score modifications and select the highest rated action - this is the most heavy in terms of performance and I'd suggest testing it a lot)
    - NPC combat - FSM (Not yet implemented), once the above brain will go into fight mode, this FSM kicks in

    I have some other brain ideas that I wish to implement, I'm not sure I'll so I haven't listed them, for a MOBA, I'd consider GOAP if it isn't too heavy (it can lead to some interesting results) or neural network (if you have the time to tweak it), or Behavior Trees.

    BTW if you want we can continue talking about our games over discord
     
    bigRUSH likes this.
  13. bigRUSH

    bigRUSH

    Joined:
    Jul 19, 2019
    Posts:
    19
    @xCeas so as I understood Your game will run in one network (like computer club where all connected to one host)? GOAP + FSM nice!
    For MOBA like games I think for learning skills and buying items GOAP is ok, and for fighting, move, using skills FSM is best solution. I like also idea of ML, when I see OpenAI plays DOTA 2, I feel like this is something unreal, not from our universe or our time :D
    Can You send me private message with your discord? We are doing almost same features (maybe for different type of games), it will be nice to consult on something with You. All my friends are app developers but I don't have anybody who is game creator, so i'm loosing motivation :(