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 vinny2 · May 28, 2012 at 01:47 AM · inputiphonetouch

GameObject following touch input, gesture and speed?

I'm curious about replicating the following behavior in Unity:

http://www.youtube.com/watch?v=syy2xt3CwHg

When the finger is in a specific area of the screen, a game object is spawned. It follows the finger gestures and when the finger is released, the gameobject is deattached. If the finger is release with previous speed (aka swipe) the gameobject is thrown.

Can i do this with the stock library or should i search for something in the Unity Store?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by hathol · May 28, 2012 at 02:26 AM

Stock library is perfectly fine for that. Just use the regular Input.touches[]. Though I would avoid using touchPhases since they are somewhat slow and unreliable. Either keep track of the pressed/released state yourself or for something a bit more fancy, you could use http://technology.blurst.com/iphone-multi-touch/ .

Comment
Add comment · Show 2 · 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 vinny2 · May 28, 2012 at 03:16 AM 0
Share

Do you know any examples of this behavior or something similar?

avatar image hathol · May 28, 2012 at 03:44 AM 1
Share

Let's see...

 GameObject yourObject = null;
 bool hasTouched = false;
 Vector2 lastPos = Vector3.zero;
 
 Update()
 {
     if(!hasTouched && Input.touchCount == 1) // pressed
     {
         hasTouched = true;
         lastPos = Input.touches[0].position;
         yourObject = Instantiate(someObjectPrefab, lastPos, Quaternion.Identity)
     }
     else if(hasTouched && Input.touchCount == 1) // finger down
     {
         lastPos = Input.touches[0].position;
         yourObject.transform.Position = Camera.main.ViewportToWorldPoint(lastPos);
     }
     else if(hasToched && Input.touchCount == 0) // released
     {
         Vector3 direction = Input.touches[0].position - lastPos;
         yourObject.Rigidbody.velocity = direction.normalized*someSpeedValue;
         hasTouched = false;
     }
 }

This is untested and 10-$$anonymous$$-hack-something-together code (I haven't Unity installed an that machine here), but it should give you an idea of what you're after

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Issue with Input.GetMouseButton (0) on mobile (iPhone) 2 Answers

Input.GetAxis("Vertical") on touch devices. 2 Answers

iPhone touch events slowdown fps?!? 2 Answers

Iphone touch not working 0 Answers

Delay before first touch position changes on iPhone 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