• 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 DaReign · May 10, 2019 at 11:02 AM · rigidbodyballrigidbody.addforce

Add force for long pass ball

Hi How to add correct forces for ball pass. For simple pass I do it that way

 rb.AddForce((target.position - transform.position) * thrust, ForceMode.Impulse);

so basicaly I calculate direction and apply some thurst (kick power). It behavior a little strange because it looks that summary force depends on how far the target.position is o_0. And second question when I want to make long pass I do it that

 rb.AddForce(transform.up * 5, ForceMode.Impulse); // this should add vertical force to move ball up
 rb.AddForce((target.position - transform.position) * thrust, ForceMode.Impulse); 

but it don't work correctly because ball sometimes go to diferent direction (because I think of this rb.AddForce(transform.up * 5, ForceMode.Impulse);)

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
1
Best Answer

Answer by tormentoarmagedoom · May 10, 2019 at 11:09 AM

Hallo.

First Qust: AddForce is a vector. Doing this;

  target.position - transform.position

You calculate a vector with the correct direction, but the magnitude of the vector depends on the distance between the 2 points. To have a better control of the force, you should convert that vector into a known magnitude vector with the same direction. Best way to do this is to Normalize the vector (so the magnitude will be always 1)


Second Qst:

Meybe the best solution if you want a parabole trajectory, is to add the vertical movement as a simple translate function (or changing directly its transform.position.y) To have a correct control of the height.

I think a good solution can be, once you know the origin and final points, you can calculate the middle point of that 2 points. Then while the object is moving increase its Y component a little each frame, until reach the midpoint (midpoint in X and Z components, as Y will change). Once reached this midpoint, decrease Y component again.

Good luck!

Bye!

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 DaReign · May 10, 2019 at 11:32 AM 0
Share

Hi thanks for answer

  1. For short pass I tried normalize vector and maybe if you also mention about that then it is right approach. I will try figure it out ;).

  2. For long pass I did stupid mistake I used transform.up insted Vector3.up the correct code shold look like this rb.AddForce((target.position - transform.position) * thrust, Force$$anonymous$$ode.Impulse); rb.AddForce(Vector3.up *5, Force$$anonymous$$ode.Impulse);

And it is working ;)

avatar image tormentoarmagedoom DaReign · May 10, 2019 at 11:39 AM 0
Share

Nice!

Using normalize, makes you know the "force quantity" independent of the distance. So its usefull to move things. You can also move it wothout forces to mantain a constant speed, using transform.translate or changing transform.position.

Good luck! Bye!

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

145 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 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 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 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 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 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 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

[PUN] Rigidbody ball synchronization 0 Answers

rolling ball movement on different axis 0 Answers

Ball rolling on platform 0 Answers

Have player fall down with platform? 0 Answers

Smooth dashing issues 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