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 smokenstein · Mar 16, 2014 at 06:15 PM · physicsrigidbodyiosvelocityforce

AddForce doesn't work when used with velocity

Hi, I'm very new to Unity and I can't get around this weird problem. I have a top down iOS game where you roll a ball around using the accelerometer and then tap to jump. I'm using rigidbody.AddForce to jump in the Y direction and the rolling movement is on the XZ plane.

What happens is that when I tap, the ball jumps but not that high and it falls to the ground very slowly. This is very odd because if I use rigidbody.AddForce() instead of rigidbody.velocity to roll the ball around, the jump works really well and it also jumps higher than before. Any ideas about what's going on here? I double checked my colliders and Rigidbody settings and all seems fine, and it even works if I don't use rigidbody.velocity, but I feel that's the best way to roll the ball around in the game so I have to use it.

BTW, the reason I use GetMouseButton(0) is so that I can try it out the jump in the Editor with my mouse. Same command accepts iOS touch also.

Any help is appreciated,

This is my code:

 moveDirection.x = Input.acceleration.x;
 moveDirection.z = Input.acceleration.y;

 if (moveDirection.sqrMagnitude > 1f)
 {
     moveDirection.Normalize();
 }
 rigidbody.velocity = moveDirection * Time.fixedDeltaTime * moveSpeed * speedFac;

             

 if (Input.GetMouseButton(0))
 {
     Debug.Log("touched");
     if (isGrounded)
     {    
         rigidbody.AddForce(0f, jumpforce * Time.FixedDeltaTime, 0f, ForceMode.Impulse);
         
         isGrounded = false;
     }
 }
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

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by smokenstein · Mar 17, 2014 at 03:33 PM

I may have solved my Issue (for those interested) - Use AddForce and ForceMode.VelocityChange

I will post a reply once I've tested it but right now that seems like my best option.

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 smokenstein · Mar 19, 2014 at 05:18 PM 0
Share

Had to raise the drag on the rigidbody and the speed to compensate for that. This made the controls more responsive like it was when I was directly manipulating the velocity. The way I got the Jump to work was by reducing the drag and the speed while the player was jumping, this made the jump look more realistic (otherwise the descend would've been super slow due to the high drag)

avatar image rockyourteeth · Mar 19, 2014 at 08:55 PM 0
Share

Cool! These tips are going to help me with my own game, cause I've been wrestling with the same problems.

avatar image
0

Answer by frogsbo · Mar 16, 2014 at 06:41 PM

velecity overrides add force and physics. it's a higher level than physics commands like force. if a button goes down to addforce, then say if addforce down, not set velocity values.

In most cases you should not modify the velocity directly, as this can result in unrealistic behaviour. Don't set the velocity of an object every physics step, this will lead to unrealistic physics simulation. A typical example where you would change the velocity is when jumping in a first person shooter, because you want an immediate change in velocity.

Comment
Add comment · Show 1 · 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 smokenstein · Mar 16, 2014 at 06:54 PM 0
Share

Thanks frogsbo, how would you recommend rolling a ball then? If I use AddForce to roll it, it will only roll in a direction until a strong enough force is applied in a different direction. What velocity gives me is a more responsive change in direction and speed and that's what I really wanted (along with being able to jump). Is there another way to make the ball jump other than AddForce?

avatar image
0

Answer by PRABHBIR123 · Jan 27, 2019 at 03:31 PM

If you @smokenstein want more info on this and a better solution then check out this. https://youtu.be/_93c-78CLak

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

23 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

Related Questions

Gravitational Object Creation for 3D Game 1 Answer

Manually Apply Cars Collision Response Force 0 Answers

Calculate velocity to set to reach a target point on a plane considering the drag. 0 Answers

Rigidbody character controller can't walk on stairs 0 Answers

Velocity powered rigidbody on a moving platform without parenting. 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