• 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
Question by behzad.robot · Jul 05, 2014 at 06:05 PM · androidmobiletouchdrag

Box Drag and throw away script for mobile?

Hi i everyone i was working on my game in which in one part the player has to Drag the boxes outta his/her way so i tried unity3d's default rigidbody dragger(Scripts Package)but it's spring like working is both good and bad but i guess it's about the best result i've got so far.The problem with this one is that once i release it goes flying up high ! Then i tried another code found here(http://answers.unity3d.com/questions/498396/how-to-click-and-drag-an-object-at-full-speed.html)but this one's too dependent to the player once i release the mouse it'll be freezed in it's place and wont keep on going which is bad for gameplay cos like this player wont be able to move lots of boxes one after another!I also tried http://youtu.be/QjUhQ4z6pF0 but it aint moving at all i did some minor changes in code but then it started moving like what was shown in the video and we were told that it was unity remote's problem(or sth like that :D)!Here's my edited version of that code:

 public var Target:GameObject;
 public var XLimit:float = 2.5;
 public var YLimit:float = 2.5;
 public var ScrollDistanceX:float;
 public var ScrollDistanceY:float;
 public var Hit:RaycastHit;
 public var layermask = (1 << 8) |(1 << 2);
 function Start () {
     ScrollDistanceX = transform.position.x;
     ScrollDistanceY = transform.position.y;
 }
 
 function Update () {
     if(Input.touchCount > 0 )
     {
         var TheTouch :Touch = Input.GetTouch(0);
         var MyRay  = camera.main.ScreenPointToRay(TheTouch.position);
         if(Physics.Raycast(MyRay,Hit,layermask))
         {
             
             if(Input.touchCount == 1)
             {
             //    Destroy(Target);
                 var ScrollDeltaX = TheTouch.deltaPosition.x;
                 var ScrollDeltaY = TheTouch.deltaPosition.y;
                 //ScrollDistanceX = Mathf.Clamp(ScrollDistanceX + ScrollDistanceX*Time.deltaTime*0.5,-XLimit,XLimit);
                 //ScrollDistanceY = Mathf.Clamp(ScrollDistanceY + ScrollDistanceY*Time.deltaTime*0.5,-YLimit,YLimit);
                 /*Target.transform.position.x = ScrollDistanceX;
                 Target.transform.position.y = ScrollDistanceY;
                 Target.transform.position.x=ScrollDeltaX*0.05;
                             Target.transform.position.y=ScrollDeltaY*0.05;
             }
         }
     }
 
 }

Anyone know how to fix this problem ?I mean u dragg a box in a path of ur own once u release it it'll keep on going a bit too!I'm looking for sth close to Corona SDK's Drag object example(Anyone who has worked with that program will probably know what i mean)or sth which is at least as smooth as bad piggies system but with the keep moving part ofcourse :(

Comment

People who like this

0 Show 0
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

0 Replies

  • Sort: 

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta on June 13. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

21 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

Related Questions

Dragging Camera based on Touch 0 Answers

Moving a GUI Image to the same position as a touch 0 Answers

Fix Rotate Object with touchscreen on X and Y axis 0 Answers

How Can I Drag the Object With Touch ? (Mobile) 4 Answers

The joystick isnt working in Unity remote 5 3 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