Search Unity

Fixing Movement

Discussion in 'Scripting' started by xReaper7x, Jun 18, 2014.

  1. xReaper7x

    xReaper7x

    Joined:
    Jan 9, 2013
    Posts:
    15
    Hello everyone,

    So I am creating a 2.5D side scroller and I have some basic movement working with Blending in Mecanim and I have gotten rotation to work. Now one problem that I am having is I need the character to move in the direction it's facing and get the movement to switch also lets say if I rotate 180 degrees facing backwards now when I click left to move forward instead of right because he is rotated now I am moving backwards instead of forwards.. if anyone wants to look at the photo's below you might get a better understanding, or even download the game and give it a go.

    NOTE: IF DOWNLOADING YOU MUST USE A PS4 OR Xbox Controller as I am using InControl for input integration.

    File: https://mega.co.nz/#!aBBVEDCb!lJlk2R113_rzGFRmDCbQDHVYqqgg-GcXhXwCYTAHMNI
     

    Attached Files:

  2. xReaper7x

    xReaper7x

    Joined:
    Jan 9, 2013
    Posts:
    15
    bump. Anyone?
     
  3. TheSniperFan

    TheSniperFan

    Joined:
    Jul 18, 2013
    Posts:
    712
    I'm on my smartphone right now so I couldn't check, but my first bet would be that you're using the wrong vector to determine the movement direction.
    Is it possible that you're using Vector3.forward instead of transform.forward?
    The former is global and therefore always points in the same direction, while the latter is local, relative to the GameObject and moves/rotates with it.
     
  4. xReaper7x

    xReaper7x

    Joined:
    Jan 9, 2013
    Posts:
    15
    Im not using a Vector at all, I am having Mecanim drive all the animations..

    So in code its like

    Code (CSharp):
    1. charAnimator.SetFloat("Horizontal", InputManager.ActiveDevice.LeftStickX);
    2.  
    3. charAnimator.SetFloat("Vertical", InputManager.ActiveDevice.LeftStickY);
    and the animator is setup like this http://imgur.com/24e6KqZ
     
  5. xReaper7x

    xReaper7x

    Joined:
    Jan 9, 2013
    Posts:
    15
    Bump? Still looking for an answer.. :(
     
  6. chrisall76

    chrisall76

    Joined:
    May 19, 2012
    Posts:
    667
    I would honestly just recommend handling the animation yourself. I've had problems using the mecanim movement.
    Also, most of the time if you want people to try your game you'll want to post a webplayer.
    I'm using InControl, you can set it up to also use keyboard input (the default FPSProfile in it does this, actually).