Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 RedDevil · Feb 06, 2017 at 04:12 PM · joysticktouchscreenevent triggeringpointerevent-handling

Touchscreen Joystick Character Control using PointerEventData

Hi, I am trying to control my character using an onscreen touch joystick. I have written this code with OnPointerDown, OnPointerUp and OnDrag and it works perfectly. The issue I am having is that this does not really replicate a real controller in the sense that if you keep the joystick pressed in a direction on a controller the movement in that direction continues. In my case if you keep the joystick pressed in a direction than it does not generate another event for movement unless i make a change in the direction axis. Is there an event or something i do not know about to do this? I have looked over the unity documentation and google searches but did not find anything usefull on what I am trying to achieve here. Note that this will be an optimised mobile game so I do not want to use fixed update or just update. Any help is apreciated. Thank you!

Update: Added code:

 public void OnDrag(PointerEventData ped)
     {
         //move joystick        
        //move character
     }
 
     public void OnPointerDown(PointerEventData ped)
     {
         OnDrag(ped);
     }
 
     public void OnPointerUp(PointerEventData ped)
     {
         //reset joystick
     }

I had not added more code as it would not be relevant to my current problem. I am moving the character about a unit in the direction of the joystick on each dragging move. The issue i am facing is that OnDrag really works only on drag and i was wondering if there is some way to make it fire events like let's say every 0.5 s while the joystick button is being hold down. At first when writing this code I had asumed that the OnPointerDown does just that ... while it is being hold down would fire events but that is really not the case.

Comment
Add comment · Show 5
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 FortisVenaliter · Feb 06, 2017 at 05:20 PM 0
Share

How can we help if you don't post the relevant code?

avatar image RedDevil FortisVenaliter · Feb 06, 2017 at 05:29 PM 0
Share

issue updated with relevant code

avatar image FortisVenaliter RedDevil · Feb 06, 2017 at 05:47 PM 0
Share

There's no actual functionality in that code...

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by RedDevil · Feb 08, 2017 at 04:28 PM

Since i could not really find a good way to do this with PointerEventData i just changed my code so that i can achieve what i was after. The way I solved the problem is by changing on PointerDown to call a coroutine of a new method called movement where i just do a yield wait for seconds and do the movement on a loop and then i changed OnPointerUp to stop that coroutine when the joystick is not pressed.

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

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

Related Questions

How to detect if a pointer(mouse,joystick) is staying in "pressed" and not moving, using event trigger? 0 Answers

Pointer Down event on a button still registering a hold even when I drag pointer away?? 1 Answer

On-Screen joystick using PointerEventData takes input from mouse drags and touch drags anywhere on screen 0 Answers

EventHandler from external DLL not firing in MonoBehaviour C# script 0 Answers

Make touch buttons stop working after finger slides off. 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