Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Top down 3d shooter script, xbox 360 controller assistance

Discussion in 'Scripting' started by Gerald Tyler, Aug 18, 2015.

  1. Gerald Tyler

    Gerald Tyler

    Joined:
    Jul 10, 2015
    Posts:
    80
    So here's what I have in my Update function for a simple 3d top down shooter using C#.

    Code (csharp):
    1.  
    2. Vector3 inputMove = new Vector3 (Input.GetAxisRaw ("leftStickHorizontal"), 0, Input.GetAxisRaw ("leftStickVertical"));
    3.  Vector3 inputRotate = new Vector3 (Input.GetAxisRaw ("rightStickHorizontal"), 0, Input.GetAxisRaw ("rightStickVertical"));
    4.  if (inputRotate != Vector3.zero) {
    5.  targetRotation = Quaternion.LookRotation (inputRotate);
    6.  transform.eulerAngles = Vector3.up * Mathf.MoveTowardsAngle (transform.eulerAngles.y, targetRotation.eulerAngles.y, rotationSpeed * Time.deltaTime);
    7.  }
    8.  Vector3 motion = inputMove;
    9.  motion *= (Mathf.Abs (inputMove.x) == 1 && Mathf.Abs (inputMove.z) == 1) ? .7f : 1;
    10.  motion *= (Input.GetKey (KeyCode.LeftShift)) ? runSpeed : walkSpeed;
    11.  motion += Vector3.up * -8;
    12.  controller.Move (motion * Time.deltaTime);
    13.  
    I did go into the input manager and set up the 4 stick inputs, on the x, y, 4th, and 5th axes (4 and 5 are for the right stick).

    So far all that's happening is my character will move left and right, but not up nor down, and won't rotate at all.
    Yes it probably would've been a lot easier using the mouse to rotate the player, but I really just wanted to get full controller functionality at the moment.

    Thoughts?
     
  2. Gerald Tyler

    Gerald Tyler

    Joined:
    Jul 10, 2015
    Posts:
    80
    Never mind, had to go back into the Input Manager and set the types to Joystick Axis.
    *EDIT*

    Actually in case anybody else does come read this, new problem...
    1) The character doesn't stop moving once I stop the input on the left stick, even increasing my drag and angular drag isn't stopping this.
    2) Any input on the right stick (The rotation) causes the player to move.

    I think I may wind up rebuilding the movement / rotation from scratch.
     
    Last edited: Aug 18, 2015
  3. Borderline Chaos

    Borderline Chaos

    Joined:
    Aug 7, 2012
    Posts:
    47
  4. Gerald Tyler

    Gerald Tyler

    Joined:
    Jul 10, 2015
    Posts:
    80
    Yeah I was just tweeking those, thanks for the link I'll go check that out now.

    *Edit*
    Wow, that's actually a really good read. Bookmarking that. Thanks again.