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
1
Question by Palanysamy · Sep 26, 2013 at 05:06 PM · inputjoystickcursorcontrollers

How can I control cursor with joystick

Hello people, I am doing a custom cursor that needs to be controlled by the joystick. To control the cursor with the mouse is quite easy, but I am trying to figure the equivalent but with the joystick axis input. To move cursor with mouse is done like this:

function OnGUI(){ GUI.DrawTexture (Rect(Input.mousePosition.x-cursorSizeX/2, (Screen.height-Input.mou.y)-cursorSizeY/2, cursorSizeX, cursorSizeY),myCursor); }

How can I do it with Joystick?

Comment
Add comment · Show 1
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
avatar image Conect11 · Sep 26, 2013 at 05:13 PM 0
Share

while it's not EXACTLY what you're looking for, I'm going through something similar, and have made some progress. (not complete, by any means, but maybe it'll help you)

http://answers.unity3d.com/questions/543403/taking-steps-to-all-gamepad-control.html

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Visual Programmer · Sep 26, 2013 at 07:03 PM

Inside of the Input Manager, you can set the joystick axis to the mouseX and mouseY. That way, you should be able to control the cursor using Input.GetAxis(Mouse X) and Input.GetAxis(Mouse Y).

Input Manager is located under: Edit-->Project Settings-->Input

and here is a mapping guide for controllers.

Comment
Add comment · Share
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
avatar image
1

Answer by Palanysamy · Sep 27, 2013 at 06:44 AM

Already figured it out: x = Input.GetAxis("Horizontal") speed Time.deltaTime; y = Input.GetAxis("Vertical") speed Time.deltaTime;

Comment
Add comment · Show 1 · Share
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
avatar image Rs31412 · May 09, 2014 at 06:48 PM 0
Share

can you tell me exactly how this makes your mouse move with your controller? Explanations of answers would be really helpful.

avatar image
1

Answer by MushayDroom · Jan 18, 2019 at 08:54 AM

Hi there ! :)

I resurrect this subject after a few years because I have trouble controlling the Unity Cursor with the Xbox controller left joystick. The context in game is this one :


  • Oculus Player with movements controlled by left Xbox joystick,

  • Pressing B Button, a Pause Menu is displaying (simple canva Camera Space),

  • Unity Cursor appear and shall "OnClick" buttons (among them : resume),


Of course, my question is about the third step of this process as I fail to recover joystick movement while canceling the one of the first step's setup. The cursor in pause menu shall be controlled by left joystick.

I'm pretty new to c sharp and i'm confused between both coding and unity's drag & droping logic on this specific task.

I will surely appreciate any help from you ! ♥

EDIT :

Now struggeling on how to constraint GUI Cursor position at screen limits and how to make the GUI cursor act like a mouse, regarding "OnClick" behavior.

 using System.Collections.Generic;
 using UnityEngine;
 
 
 public class XboxCursor : MonoBehaviour
 {
 
     public Vector3 originalPosition; //Original Position stored for "Start at Center position" Cursor behavior
     private Vector3 startPos;
     private Transform thisTransform;
     public float sensitivity = 0.2f;
 
 
     void Start()
     {
         thisTransform = transform;
         this.transform.position = originalPosition; //Wrong method for reset to center position...
     }
 
     void Update()
     {
 
         // Joystick Axis Acting
         Vector3 inputDirection = Vector3.zero * sensitivity;
         inputDirection.x = Input.GetAxisRaw("Horizontal") * 0.1f;
         inputDirection.y = Input.GetAxisRaw("Vertical") * 0.1f;
         thisTransform.position = startPos + inputDirection * sensitivity;
         startPos = thisTransform.position;
 
 
         //Screen Constraint  -- Not Working at all for some reason
         this.transform.position = new Vector3(Mathf.Clamp(transform.position.x, -1f, 1f),
                         Mathf.Clamp(transform.position.y, -2f, 2f), transform.position.z);
         
         // Mouse OnClick Mimetism
         if (Input.GetButtonDown("Button A"))
         {
             Input.GetMouseButtonDown(0);
             Debug.Log("Mouse Click !"); //But still at real mouse position ! xP
             
            //TP Mouse (Bad Opt)
            //Raycast GUI (Good Opt... Searching Doc...)
         }
     }
 }



EDIT : Leaving this here, but subject abandonned after new UX project approach.

Comment
Add comment · Share
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
avatar image
0

Answer by leegod · Jan 27, 2021 at 07:29 AM

I want to know about this... how to make virtual mouse cursor for control via Nintendo Switch pro controller connected to PC.

Comment
Add comment · Share
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

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

20 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 avatar image

Related Questions

Get DPad input value via GetButton instead of GetAxis? 8 Answers

Add Cursor (Top-Down-Shooter) 1 Answer

How to get input from wheel(car direction) joystick? 1 Answer

Is there a way to create a floating JoyStick using the On-Screen Stick component? 0 Answers

Joystick Zone + Screen-swipe touch input clash. Solution??? 1 Answer


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