Search Unity

Not getting inputs right!

Discussion in 'Scripting' started by robertseadog, Sep 20, 2005.

  1. robertseadog

    robertseadog

    Joined:
    Jul 23, 2005
    Posts:
    374
    Hi all, Im back working on my trasform script now, and assigned it to a root joint of a mesh..

    Im using this code but I want the thing to move in the x, and z axsis only.. Not working!

    Code (csharp):
    1.  transform.Translate (Input.GetAxis ("Horizontal") * (20 * Time.deltaTime), 0, Input.GetAxis ("Vertical") * (20 * Time.deltaTime));
    I have tried altering it in all possible directions and it moves in "x" but not in "Z", instead it moves in Y!? How do I change that (Im guessing that "Vertical" is not a promising word here)?
     
  2. robertseadog

    robertseadog

    Joined:
    Jul 23, 2005
    Posts:
    374
    Maybe Im not explaining this the way I should;

    I have a mesh, this mesh I would like to transform in the X and Z axis when the user press the buttons:
    Code (csharp):
    1.  
    2. X+ = Right arrow
    3. X- = Left arrow
    4.  
    5. Z+ = Down arrow
    6. Z- = Up arrow
    7.  
    So I thought I could just use Horizontal and Vertical for this job, and assign them in the x and Z slots of the Transform.

    Appearently not! :eek: so dear people, Any suggestions?

    Thanks!
     
  3. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    I presume you have this inside the Update function:
    Code (csharp):
    1.  
    2. function Update()
    3. {
    4. transform.Translate (Input.GetAxis ("Horizontal") * (20 * Time.deltaTime), 0, Input.GetAxis ("Vertical") * (20 * Time.deltaTime));
    5. }
    6.  
    The code you have seems like the way to go.
    Do you see the values of the transform change in the inspector?
     
  4. BasketQase

    BasketQase

    Joined:
    Sep 12, 2005
    Posts:
    97
    Yeah, that code looks right to me. "Vertical" just refers to the name of the input. If you went to Edit->Project Settings->Input, you could just as easily change it to "zAxis" or "ForwardBackward" or "Lemonade." You'd then refer to it by that name in script instead of "Vertical".

    As far as what it's doing now, I would double check that you have no other code affecting the movement of your object, and that you're visualizing the right axis in 3D-space. I know I get tripped up all the time expecting Z to be the vertical axis.

    You could also try testing your code with constants instead of the input variables. For instance, you could put transform.Translate(1, 0, 1) in your update function and see how it moves.

    Oh, and translate might use local coordinates to determine the move, so you might check that your object isn't rotated 90 degrees in some direction, causing your axis to be rotated as well.
     
  5. robertseadog

    robertseadog

    Joined:
    Jul 23, 2005
    Posts:
    374
    I think the latter might be the problem.. I'll check it thanks!
     
  6. robertseadog

    robertseadog

    Joined:
    Jul 23, 2005
    Posts:
    374
    No wait a minute here; It isn't! When I look in the inspector the now called Xaxis is really the Y Axis!!

    :eek:
     
  7. BasketQase

    BasketQase

    Joined:
    Sep 12, 2005
    Posts:
    97
    Confusing . . . :?

    Does that mean you've got it figured out and doing what you want?
     
  8. robertseadog

    robertseadog

    Joined:
    Jul 23, 2005
    Posts:
    374
    No.. Hehe..

    I don't get this at all! It doesn't feel like a bug either, but I can post an example here if you would look though it (?).
     
  9. BasketQase

    BasketQase

    Joined:
    Sep 12, 2005
    Posts:
    97
    Sure, I can peek under the hood and see if I notice anything off :wink:
     
  10. robertseadog

    robertseadog

    Joined:
    Jul 23, 2005
    Posts:
    374
    Not sure still, but a normal cube works just fine.. I think Maya's joints get screwed up or something in Unity, or maybe I set it up in a wrong way in Maya (the Axis I mean!).. But it looks just fine ( the transform tool is pointing upwards-)

    Anyway the good thing is that you don't have to bother about it, but thanks for the help! ;)