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 vulgarknight · Feb 08, 2013 at 08:05 PM · rigidbodyinstantiatebuggravityforce

Applying force to a rigidbody

I am writing script for a prototype game and I have run into an issue with force. I have a bullet prefab with a rigidbody and a box collider. The rigidbody is not kinematic and is affected by gravity. I instantiate this bullet with a pretty standard instantiate function, spawning it in front of my characters face (because why can't I shoot a bullet out of my face?) and apply force with bullet.rigidbody.AddForce(transform.forward * 2000). When I hit space (my fire button) the bullet gets spawned, but only receives a small amount of force and falls to the ground rather quickly. No matter what value I use in place of the 2000, I get the same effect. Thanks in advance for any help.

Comment
Add comment · Show 1
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 vulgarknight · Feb 08, 2013 at 09:47 PM 0
Share

No, there is no collision occurring, but after a little testing, I found that when I comment my AddForce line, I get no change in effect. $$anonymous$$aybe transform.position in the AddForce parameter is set to 0? And if that's the case, no matter what number I multiply it by, it would obviously have no effect.

2 Replies

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

Answer by Neinth · Sep 17, 2013 at 10:30 PM

Not sure if this is answered or not,but the problem is "addForce" is a one time deal.In order to keep momentum up you'd need to "addForce" each frame.

You could also reduce drag,which 1 single "addForce" would start it moving,and it would slow down as it moved relative to the drag amount.You could also add a method to counteract gravity so that it still falls,but based on current force applied,add force upwards just under the gravity settings of project.0 drag would make it never slow down over distance/time unless you changed it's force manually over distance/time.

I do believe you could use "setVelocity" as well,not 100% sure how that works with drag and gravity though.

For a projectile type I'd track distance it has traveled,and set the "z" axis(how fast forward) and "y" axis force(used to counter gravity) based on that.This would give you a controllable bullet drop rate over set distances,as well as base the damage when it hits something on distance.Heavier bullets would drop faster,while maintaining forward momentum,and lighter ones would lose forward momentum faster,but drop slower.

Then again I am still learning,and that might be over complicating things.

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
avatar image
0

Answer by vulgarknight · Feb 08, 2013 at 09:40 PM

The mass value is set to 0.01, not very much, but I'm not very familiar with mass values in Unity. Is that a small value? Maybe something else is affecting the bullet mass?

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

11 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

Related Questions

What's the Rigidbody's gravity unit? 1 Answer

How to hit gameobjects to go into the opposite direction of hit? 1 Answer

Realistic/No gravity spaceship movement? 1 Answer

adding force to an instantiated gameobject in required direction 0 Answers

Change rigidbody's jumping speed 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