• 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 kishsolanki · Jul 24, 2015 at 10:45 AM · addforceforcemode

how to give force to ball from slow to fast....?

Hey guys... I have a game in which I am giving force to the ball(sphere) by

         rigidbody.AddForce (new Vector3 (0, 0, BallSpeed), ForceMode.Impulse);

in which BallSpeed is the public variable that is used to give value from the script inspector. If I keep smaller or less value of BallSpeed variable, then the ball won't reach the desired distance and stop in between the way. and if I put larger value then the ball goes speed like bullet of gun(actually not as fast as bullet, but goes very fast in just a second). So what I wanna do is that I wanna give force to the ball so that it can startup slowly and reach the desired destination with the same force. There are gameobjects in front of the ball. So i want to let them down by my ball. but want to throw my ball slowly but at the time of the collision with the gameobject, the force should remain same(Like bowling ball which thrown slowly but falls the pins very easily). So I want to do the same like bowling ball force...!

Sorry for my poor english guys.... any suggestion/solution appreciated!

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

Answer by KdRWaylander · Jul 24, 2015 at 11:00 AM

Hi,

If BallSpeed is your final value, you need to multiply it by a value between 0 and 1 and make this value start at 0 and gradually rise to 1.

 float coeff = 0.1f;
 
 void Update () {
    if (coeff < 1){
       coeff *= 1.06; //find by how much you want to rise it at each frame
       // or coeff = Mathf.Sqrt(1.5f * coeff)
       // ... it depends on which shape of accel you want
    }
    rigidbody.AddForce (new Vector3(0, 0, coeff * BallSpeed), ForceMode.Impulse);
 } 

Comment
Add comment · Show 6 · 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 kishsolanki · Jul 24, 2015 at 12:10 PM 0
Share

by multiplying it to coeff, its stopped moving, I mean addforce not working.

avatar image KdRWaylander · Jul 24, 2015 at 01:42 PM 1
Share

Ahah my bad, that's because i put the initial value of coeff to 0, so even if i multiply it by 150, il will still be 0 ^^

change float coeff = 0; to float coeff = 0.1f;

avatar image kishsolanki · Jul 27, 2015 at 06:39 AM 0
Share

thanks dude, its working, not like what I expected... but I will update it. Thanks again!

avatar image KdRWaylander · Aug 03, 2015 at 06:51 AM 0
Share

What do you mean by "not what you expected" ?

avatar image kishsolanki · Aug 03, 2015 at 07:10 AM 0
Share

when I first time add force to the sphere, it is not giving the force, but it gives 1/10th of force to sphere.. That wasn't I expected

Show more comments

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

2 People are following this question.

avatar image avatar image

Related Questions

AddForce/ForceMode.Impulse 1 Answer

Adding impulse force cancels out gravity force on collisions. 1 Answer

How do i make the Impulse i give to my Player not be lowered by acceleration of gravity? 1 Answer

Difference and uses of rigidbody force modes ? 2 Answers

Addforce - bug with jump 2 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