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 aleem.razzaq09 · Jan 07, 2014 at 11:41 AM · 2dtransformtouch

Change Input.GetTouch(0).deltaPosition to object transform position in Unity 4.3 for 2D

Hi, I am new in Unity 3d, I want to move ball on same direction when user tap on ball and move his finger. I got few hints to get user's finger position from "Input.GetTouch(0).deltaPosition;" and get object's position "transform.position" but "transform.position" give me position according to scene view and "Input.GetTouch(0).deltaPosition;" give position according to device screen. How can I convert "Input.GetTouch(0).deltaPosition;" to "transform.position" scene view wise or vice versa, so that it'll be easy for me to move ball, because I am getting confuse with different position. Kindly help me on this and suggest me better approach to accomplish this task. Thanks in advance.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by ArkaneX · Jan 07, 2014 at 01:21 PM

deltaPosition doesn't contain your finger position, but position change between frames.

Comment
Add comment · Show 4 · 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 aleem.razzaq09 · Jan 07, 2014 at 01:53 PM 0
Share

I am using this code to move position of my object while on tap. Vector2 fingerPosition = Input.GetTouch(0).position; Vector3 worldPosition =camera.ScreenToWorldPoint(new Vector3(fingerPosition.x,fingerPosition.y,0)); transform.position = worldPosition; and app gets crash when I tap on object. I don't know why this happening.

avatar image ArkaneX · Jan 07, 2014 at 02:01 PM 0
Share

Please post the error you get, but most probably this is related to the fact that if you want to use '`camera`' variable, current game object should have Camera component attached. Does your game object have camera component? If not, you can use Camera.main.ScreenToWorldPoint (assu$$anonymous$$g your camera is tagged as main camera).

avatar image aleem.razzaq09 · Jan 07, 2014 at 02:13 PM 0
Share

Actually, Its getting crash on debug mode and its not getting crash on device without debugging mode, but position not changing. Just for information I am using raycast to detect object and then change its position according to finger move. I can also change by raycast but I am not doing like this because my task is bit different. I want to throw object as fast as it pulled back. $$anonymous$$indly share with me your experience how to accomplish this task. Thanks :)

avatar image ArkaneX · Jan 07, 2014 at 02:22 PM 0
Share

You still haven't posted the error you get. Without this info, it's hard to proceed...

avatar image
0

Answer by darthtelle · Jan 07, 2014 at 12:50 PM

Try passing the position of your finger touch into Camera.ScreenToWorldPoint(). To get the position of your "mouse" on screen you can using Input.mousePosition. To get a touch event you can add an entry to the Input Manager for the mouse, and use Input.GetButton() to determine whether the button is being held down.

e.g.

 if(Input.GetButton("Mouse"))
 {
 Vector 3 fingerPosition = Input.mousePosition;
 Vector3 worldPosition = Camera.ScreenToWorldPoint(fingerPosition); 
 transform.position = worldPosition;
 }
 


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 Bunny83 · Jan 07, 2014 at 01:28 PM 0
Share

That doesn't make much sense either. deltaPosition contains "delta" information and not a position. It's x and y values represent the change between the last update of the touch device. You might want to use position. $$anonymous$$eep in $$anonymous$$d that ScreenToWorldPoint requires a 3 component position. Since the z value is implicitly 0 it affects the resulting worldposition.

avatar image darthtelle · Jan 07, 2014 at 01:35 PM 0
Share

In that case, to get the actual position of the touch on screen, use Input.mousePosition which returns the current mouse position. To get a touch event, use Input.GetButton("$$anonymous$$ouse") with an entry in the Input$$anonymous$$anager to the mouse. This is then treated as a finger on the screen.

EDIT: Updated my answer to take this into account.

avatar image
0

Answer by raimon.massanet · Jan 07, 2014 at 12:47 PM

You should use something like Camera.ScreenToWorldPoint:

http://docs.unity3d.com/Documentation/ScriptReference/Camera.ScreenToWorldPoint.html

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

22 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

Related Questions

Dragging a 2D sprite with touch 1 Answer

Drag+an+object+to+touch+position(Problem) 0 Answers

Random Movement : 2d 1 Answer

Move object by touch input 5 Answers

A node in a childnode? 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