• 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
Question by Joshua · Feb 20, 2011 at 09:00 PM · instantiatevelocityaddforcespeed

Rigidbody.AddForce not working

First of all: upon searching I found a lot of similar questions but none seemed to apply. The object (cannonball I'll call it cb) is a rigidbody, non-kinematic and is spawn outside of the cannon at an empty object to specify location.

I'm relatively new to scripting and didn't want to bother anyone but I spend several hours the past two days trying to fix and I can't =\

What happens is that the cannon rotates along it's base to follow the player around and always aim at him. Once every second it will instantiate a prefab named Cannonball. I try to apply a force/velocity to this cannonball along the forward/z axis (I've checked, the cb is instantiated with all axis as I'd want them, y upwards and z pointing at player ignoring height.) The applied force nor the velocity (I tried both) seems to work though, the cb just spawns and slowly by gravity falls to the ground and rolls off the hill. I tried huge values for AddForce as well, won't work.

Script is:

if(shouldIShoot) { var cb = Instantiate(bulletPrefab, transform.Find("CannonSpawn").transform.position, Quaternion.identity);

     cb.Rigidbody.AddForce(transform.forward * 3000000);

     shouldIShoot = false;}

Help would be greatly appreciated, preferably in the form of a concrete example of how it should look like, because I'm still new to js :)

Comment

People who like this

0 Show 0
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
Best Answer

Answer by kkaploon · Feb 20, 2011 at 09:57 PM

Try this:

cb.rigidbody.AddForce(transform.forward * 30);

Rigidbody is the class, rigidbody is the instance of it, and that's what you want to change.

Comment
Matthew A
Joshua
bowentw

People who like this

3 Show 4 · 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 Joshua · Feb 20, 2011 at 10:10 PM 0
Share

Thank you so much, you have no idea how much you've helped me! This was driving me absolutely insane to the point of ragequiting on my project xD. I feel like such a fool now.

avatar image Joshua · Feb 20, 2011 at 10:12 PM 0
Share

Small bonus question: Is there anything else I can do to credit you for this other then clicking the (^) button? :)

avatar image kkaploon · Feb 20, 2011 at 10:13 PM 0
Share

Don't feel like a fool, I had this kind of thing happen to me more than I could count. Happens to everybody.

avatar image kkaploon · Feb 20, 2011 at 10:14 PM 0
Share

Don't worry about it, that's enough.

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.

Update about the future of Unity Answers

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta later in June. Please note, we are aiming to set Unity Answers to read-only mode on the 31st of May in order to prepare for the final data migration.

For more information, please read our full announcement.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

How can you instantiate a prefab with an initial burst of speed using ForceMode2D.Impulse? 2 Answers

Apply same amount of force even after gameObjects are fixed joint 0 Answers

Gravitational pull without losing speed 1 Answer

Velocity and AddForce Problems 0 Answers

[C#] Recreating object A's velocity relative to object B 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