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 mmangual_83 · Jan 13, 2014 at 05:03 PM · c#gestures

How to apply force to an object?

I am using a gesture API to detect gestures that the user will use to move objects in a 3D space. I just wanted to know how to add force to an object that has a rigid body. Lets say that i do a swipe gesture and I want it to take in the velocity of the swipe, the position of the swipe (start point and end point) and in the end it determines how fast the object moves across a surface.

I am new to the whole gesture recognition and all I want to know is how to get started. Can anyone help me? Many thanks in advanced!

Comment
Add comment · Show 10
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 poncho · Jan 13, 2014 at 05:31 PM 0
Share

RigidBody.AddForce(endpoint - startpoint) could do the trick

avatar image mmangual_83 · Jan 13, 2014 at 05:38 PM 0
Share

@poncho Thanks I will give it a try and let you know

avatar image robertbu · Jan 13, 2014 at 05:57 PM 0
Share

Expanding on @poncho's comment:

 rigidbody.AddForce((endpoint - startpoint) * factor);

This is a starting point. As a pure guess with an object of mass 1.0, 'factor' will be around 20. This will add force based on the length of the stroke, not the speed of the stroke. And it will not be platform independent.

avatar image mmangual_83 · Jan 13, 2014 at 06:12 PM 0
Share

@poncho no, it didnt work, but thanks for your help anyways.

avatar image mmangual_83 · Jan 13, 2014 at 06:23 PM 0
Share

@robertbu I tried that but the object is not moving. What is in your "factor" variable. $$anonymous$$aybe I'm doing it wrong. I even went ahead and just put 20 within the factor variable.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Benoit Dufresne · Jan 19, 2014 at 02:38 AM

Robertbu and poncho are correct.

The function you need is Rigidbody.AddForce(Vector3 force). It just needs to be strong enough to move your object's mass.

I'd recommend something like:

     rigidbody.AddForce((endpoint - startpoint).normalized * force);

to experiment. This will ignore the magnitude of your movement and just apply "force" newtons to your object. Make sure force is greater than the object's mass and see if that works!

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

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

A node in a childnode? 1 Answer

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

Animate the scaling of a gameObject 4 Answers

Not getting component properly 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