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 Dukeofvampires · Sep 21, 2011 at 04:20 PM · rigidbodyiphoneaddforceiphonetouch

Add impulse force using input.touch

I have a code like this:

if (Input.touchCount > 0) {

         var theTouch : Touch = Input.GetTouch (0);        
         
         var ray = Camera.main.ScreenPointToRay(theTouch.position);
         if(Input.touchCount == 1){        
             
                  if(Physics.Raycast(ray,hit,50,layerMask)){
                
                      var scrollDeltaX = theTouch.deltaPosition.x;
                     var scrollDeltaY = theTouch.deltaPosition.y;
                     scrollDistanceX = scrollDistanceX+scrollDeltaX;
                     scrollDistanceY = scrollDistanceY+scrollDeltaY;
                     var dir : Vector3 = Vector3(scrollDistanceX, scrollDistanceY, 0);
                     
                     hit.rigidbody.AddForce(dir*coef,ForceMode.Impulse);
                     
                 }            
             
         }

So the idea is to apply an Impulse force to a rigidbody object when user perform drag gesture on it. But it should be applied only once per gesture, so that force doesn't multiply during one finger movement.

I tried to use timer (AddForce applied once per second), i works some how but with strange behavior. (Response was not constant).

I think i need to use some Touch.phase, but i'm not sure how.

Thanks for your response;

Comment
Add comment · Show 3
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 syclamoth · Sep 21, 2011 at 05:02 PM 0
Share

So, do you want the force applied at the end of the gesture, or when the gesture reaches a given threshold point? Force$$anonymous$$ode.Impulse should only be used for one-off forces, not every frame the way you are using hit here.

avatar image Dukeofvampires · Sep 21, 2011 at 05:27 PM 0
Share

Yes, i want force to be applied at the end of the gesture.

Force$$anonymous$$ode.Impulse should only be used for one-off forces

example, please.

avatar image syclamoth · Sep 22, 2011 at 12:05 AM 0
Share

Well, in this case, an example would be actually what you are doing here.

Well, Touch.phase has what you need here- you need to apply the force when the touch is released, but at the same time you need to store information about each touch in some data structure (depending on the detail you need for your gestures, this could be either just the start point, or a list of points generated over the course of the touch) when the touch has not been released. Touches are sorted by integers, no? Then you can just use a list of Vector2 arrays, and access it by number whenever you have a given touch message. Then, at release, you can ask the list for the information it has collected, and clean it out at the same time ready to be used again!

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

making perpetual movement 1 Answer

Does rigidbody.AddForce work for the iphone? 1 Answer

how do i move a object with direction of touch 0 Answers

RigidBody.AddForce not working 1 Answer

Unity iPhone: AddForce to Object after Touch 0 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