Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Jiraiyah · Feb 13, 2015 at 02:20 AM · fpsjoystick

problem setting up a game pad

Hello everyone, this is my very first time trying to make a game pad work with unity 3d the script I am using here is very basic one :

 #pragma strict
 
 public enum RotationAxis
 {
     MouseX = 0,
     MouseY = 1
 }
 
 var RotationAxisRotationXY = RotationAxis.MouseX | RotationAxis.MouseY;
 var SensitivityX : float = 400f;
 var MinimumX : float = -360f;
 var MaximumX : float = 360f;
 var RotationX : float = 0f;
 var OriginalRotation : Quaternion;
 var RotationY : float = 0f;
 var MinimumY : float = -25f;
 var MaximumY : float = 25f;
 var SensitivityY : float = 400f;
 var XQuaternion : Quaternion;
 var YQuaternion : Quaternion;
 
 function Start () 
 {
     
 }
 
 function Update () 
 {
     if (RotationAxisRotationXY == RotationAxis.MouseX)
     {
         RotationX += Input.GetAxis("Mouse X") * SensitivityX * Time.deltaTime;
         RotationX = ClampAngle(RotationX, MinimumX, MaximumX);
         OriginalRotation = XQuaternion = Quaternion.AngleAxis(RotationX, Vector3.up);
         transform.localRotation = OriginalRotation * XQuaternion;
     }
     if (RotationAxisRotationXY == RotationAxis.MouseY)
     {
         RotationY -= Input.GetAxis("Mouse Y") * SensitivityY * Time.deltaTime;
         RotationY = ClampAngle(RotationY, MinimumY, MaximumY);
         OriginalRotation = YQuaternion = Quaternion.AngleAxis(RotationY, Vector3.left);
         transform.localRotation = OriginalRotation * YQuaternion;
     }
 }
 
 static function ClampAngle(angle : float, min : float, max : float) : float
 {
     if (angle < -360)
         angle += 360;
     if (angle > 360)
         angle -= 360;
     return Mathf.Clamp(angle,min,max);
 }

The setting on input manager :

alt textalt textalt text

The screen shot of the problem,

alt text

as you can see, the calibration software shows that I am perfectly moving only on one axis, also, I checked the settings on the camera and fps control over and over again, the fps control is on rotate x and camera on rotate y, when I use the right analog stick, it rotates the camera correctly, when I move the character forward/backward everything is ok, but as soon as I move the character left and right the camera starts rotating up and down, I even tried the new sample asset's fps prefab and same error there. What am I doing wrong here?

and here is the controller script

 #pragma strict
 
 public var MoveSpeed : float = 50;
 public var JumpSpeed : float = 55;
 public var MoveDirection = Vector3.zero;
 public var Gravity : float = 45;
 public var Grounded : boolean = false;
 
 private var controller : CharacterController;
 
 function Start () 
 {
     controller = gameObject.GetComponent.<CharacterController>();
 }
 
 function Update () 
 {
     if (Grounded)
     {
         MoveDirection = new Vector3(Input.GetAxis("Horizontal"),0,Input.GetAxis("Vertical"));
         MoveDirection = transform.TransformDirection(MoveDirection);
         MoveDirection *= MoveSpeed;
     }
     if (Grounded)
     {
         if (Input.GetAxis("Jump"))
         {
             MoveDirection.y = JumpSpeed;
         }
     }
     MoveDirection.y -= Gravity * Time.deltaTime;
     var flags = controller.Move(MoveDirection * Time.deltaTime);
     Grounded = (flags & CollisionFlags.CollidedBelow) != 0;
 }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Mobile Joystick - How to increase the touch area 0 Answers

How do I properly rotate an FPS camera with a joystick? 1 Answer

Changing the size of the mobile FPS control GUI? 0 Answers

How to use a PS3 controller to control an FPS 2 Answers

android fps 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges