Input

How can u add joystick, and trigger input. I can do all of the other buttons, except for them. They seem to have to have something diferent.


Answer this question

Input

  • Aaron L

    i get this when i try yours dczraptor
    Error 1 Cannot implicitly convert type 'float' to 'int'. An explicit conversion exists (are you missing a cast )

    idk here is the code:

    PlayerX += GamePad.GetState(PlayerIndex.One).Triggers.Right * (float)gameTime.ElapsedGameTime.TotalSeconds;







  • Andrew Sears - T4G

    Don't do both of these at once; i'm just showing how you would use either one.

    Vector2 position;

    public override void Update(GameTime gameTime)

    {

    // make the guy move in the +X direction based on how much the right trigger is pressed

    position.X += GamePad.GetState(PlayerIndex.One).Triggers.Right * (float)gameTime.ElapsedGameTime.TotalSeconds;

    // make the guy move based on the joystick. 1 unit per second.

    position += GamePad.GetState(PlayerIndex.One).Thumbsticks.Left * (float)gameTime.ElapsedGameTime.TotalSeconds;

    }



  • AndyL

    For joystick, you can do

    Vector2 leftStick = GamePad.GetState(PlayerIndex.One).ThumbSticks.Left;

    where leftStick.X is the horizontal movement of the stick, and leftStick.Y is the vertical movement.

    For the triggers,

    float rTrigger = GamePad.GetState(PlayerIndex.One).Triggers.Right;

    rTigger will be a value from 0.0 to 1.0. 0.0 means the button is not being pressed, 1.0 means the trigger is being pressed all the way down. Any value in between corresponds to a level of press.



  • Glen Satuito

    In the XNA Game Studio Express Documentation there is some simple tutorials on Going Beyond: Game Studio Express in 3d, inside this section if you follow the tutorials it goes through displaying a model on the screen and moving it using your controller. You should be able to see how it is used in those examples. Also if you are having trouble with the tutorials there are some video versions that you can watch on the XNA Home page.

    Link to the Video Tutorials...



  • jasse_91

    so then you would just put that code into an if statement, or something. Could u show me an example of pullting the trigger to make a guy move, like if(....) then do ..., or event the joysitcks

  • achalk

    Nvrmnd got it to work, it was because i didn't have a vector2 for my positon

    but would i have to do the same for the right trigger, to see if it is pulled, like if i wanted to make something fire by using the right trigger.

  • Input