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 mdinizzz · Mar 20, 2012 at 06:40 PM · ioscontrollerjoystick

How to use the joystick to control the character

I have a question about use the joystick to control the character.

How to use the joystick to control the character?

I just can control the character by keyboard (use the "Input.GetAxis")

if I need to change it into the "Touch"(it means I have to use the GUIText to control the charater)

Chould teach how to do it or show me the script?

Thanks a lot.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by DaveA · Mar 20, 2012 at 06:58 PM

I assume you have read this: http://unity3d.com/support/documentation/ScriptReference/Input.html especially this: http://unity3d.com/support/documentation/ScriptReference/Input.GetAxis.html but if you are asking how do do this with 'touch' on a mobile device? Look in Standard Assets (Mobile) for the joystick controls which put pictures of joystick on screen you can use like the real thing.

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 jbahr19 · Jul 10, 2015 at 08:37 AM

Alright after spending the better part of a day and half on trying to build my own joystick in the HUD (screen view canvas), I found this wonderful little bit of information (http://docs.unity3d.com/ScriptReference/Vector3.ClampMagnitude.html). However; applying that to a specific UI object was a tad difficult. Basically you have to define the component you want to move inside your HUD. For me I was trying to move an empty object with an child image to have an on-screen joystick.

alt text

The following code is what I got to work with my setup. Hope this helps!

using UnityEngine; using System.Collections;

public class SelectorMovement : MonoBehaviour {

 public RectTransform rt;
 public Vector3 centerPt;
 public float radius;

 void Start (){
     rt = GetComponent<RectTransform> ();
     centerPt = rt.anchoredPosition;
 }

 void Update() {
     Vector3 position = new Vector3 (rt.anchoredPosition.x, rt.anchoredPosition.y, 0);
     Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0);
     Vector3 newPos = position + movement;
     Vector3 offset = newPos - centerPt;
     rt.anchoredPosition = centerPt + Vector3.ClampMagnitude(offset, radius);
 }

}


screenshot.jpg (175.5 kB)
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 game-dev333 · Jul 10, 2015 at 05:31 PM 0
Share

hi..can you post complete script?

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

6 People are following this question.

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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

problems with virtual joystick for IOS 1 Answer

Getting Joystick Input from Matricom G-Pad BX? 0 Answers

Make Player face where Joystick is pointing? 6 Answers

How do I check what input device is currently beeing used? 4 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