Search Unity

Unsure what the best-practices are for a setup like this.

Discussion in 'General Discussion' started by Redz0ne, Apr 13, 2015.

  1. Redz0ne

    Redz0ne

    Joined:
    Oct 19, 2010
    Posts:
    332
    More a general question as to what you think the best practices are for making a game with a setup like this.

    Right now the project I have uses an empty game-object with the character controller and such for movement and all the code for controlling movememnt and movement-related stuff there. The model is nested as a child and I have it rotating as needed (i.e. If I have the player moving to the left and want the model looking to it's right, the model rotates towards the thing to the right it's supposed to be looking at.)

    Thing is, I've come up a realization that for some things I want it to do I may need to use the root-motion controls (mostly for things like dashing knife strikes or other things that coding it would be a nightmare of tweaking to get it to look "just right" whereas if I have the animation control it, that would likely be easier since I could animate the movement rather than tweaking values and then testing to see if I got it right.)

    So, I'm unsure if this is the right way to go about it. What would you say is the best way (in your personal opinion) to get something like this done where movement sometimes needs to be controlled by the animation and sometimes it needs to be controlled by the code?
     
  2. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,619
    There's no one right answer, and what works best will depend on your game and the kind of actions you need to do. The more you can tell us the more we might be able to help.
     
  3. Redz0ne

    Redz0ne

    Joined:
    Oct 19, 2010
    Posts:
    332
    For the specifics, the game I'm focusing this on right now is a third-person top-down shmup. I have the dual-stick firing mechanism set up (ala: Geometry wars) but not every weapon that the player can gain access to is a gun or projectile-based system. Some of them are melee fighting things.

    For example, I have the soldier. His melee weapon is a combat knife. I want to have it set up that as that weapon is improved (skill points) it unlocks more combinations. So, it starts as a basic jab (no animation movement needed) but can chain into a sort of -> Ho -> Ha ha -> Guard -> Turn -> Parry -> Dodge -> Spin -> Ha -> Thrust. For this I'll need to make him lunge forward on some spots. While I could make the animation return back to the center point, I would like to use the root motion systems since animating it would be far easier than having to approximate the movement in code (which would be a trial and error thing and a nightmare to set up for each character since their melee attacks/combo attacks will have differences.) (edit) Also because if I can do the movement via animation, it'd likely be a more organic feel to that motion (I'm not the greatest animator in the world but I can manage.)

    When I've tried it at first, the player object itself will move outside of the main parent object that controls the movement since the model is a child of the player matrix thingamabob.

    Now, if I could somehow reach in to that, grab the root motion data, apply it to the parent object (or make the root motion on that one apply itself to the parent as opposed to the model) that might do it... But regardless, I'm still unsure what the most logical way of accomplishing this would be. If this requires a re-do of how I have it set up I'm sure I could find a way to do that... Still, I'm at a loss.
     
  4. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,913
    There is a new Generate Root Motion Curves button in Unity 5 for animations made inside Unity. You could technically use this to seperate the movement from the attack anim, so you could animate "on the spot" as usual. The movement animation (made inside unity) would be placed on the CharacterController, whereas the attack animation would be on the child character model.

    The problem is that collisions won't work, so you'll need some detector gameobject that does that.

    If you want root motion in general, I think the model has to be the parent. I'm not sure there's another way around that, but obviously you lose some options by doing that.