• 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 John 17 · Oct 21, 2010 at 06:57 PM · rigidbodyaddforce

AddForce wont apply force to gameobject...help please

I am created a top-down shooter and i have the player rotate towards the mouse...i have a script attached to the player to instantiate a grenade to be thrown when the mouse button is clicked. The grenade shoots BUT just drops right to the ground, no force is applied once its instantiated...here is my code...

var speed = 40; var cratePrefab:Transform;

//static var canShoot = false;

function Update() { if(Input.GetButtonDown("Fire1")) { //only shoots if player has ammo if(Collisions.GRENADE_AMMO > 0) { Collisions.GRENADE_AMMO -= 1; //GameObject.Find("g_count").guiText.text=""+Collisions.GRENADE_AMMO; var crate = Instantiate(cratePrefab,GameObject.Find("shootpoint").transform.position,Quaternion.identity); crate.rigidbody.AddForce(Vector3.forward * speed); } } }

all help is greatly appreciated!!

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 VS48 · Oct 21, 2010 at 07:23 PM 0
Share

Ensure that the crate rigidbody is not kinematic.

1 Reply

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

Answer by skovacs1 · Oct 21, 2010 at 07:09 PM

Make sure that your crate is not colliding with the one throwing it. You can use Physics.ignoreCollision or make sure to offset it to avoid that problem.

If that's not it, assuming your cratePrefab has a non-kinematic rigidbody and depending on your scale, your speed is probably too low to either be noticeable or to overcome your drag or other factors. Forces don't actually represent speeds directly, but force applied and that's why they have to be much larger. With a force of 40, your object should achieve a speed of 4 units forward initially. Try something like 400 or 4000. If you want to force the initial speed and direction, you could also use crate.rigidbody.velocity to set the speed explicitly.

Comment
Add comment · 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 John 17 · Oct 21, 2010 at 07:18 PM 0
Share

I got it to actually SHOOT using velocity, but now its only moving in the Z direction no matter where i am ai$$anonymous$$g. I'm new to unity and i understand why its doing that but how can i change this:

crate.rigidbody.velocity = Vector3(0,0,speed);

so that the velocity is applied to wherever the player is facing...something like transform.position...

avatar image John 17 · Oct 21, 2010 at 07:21 PM 0
Share

maybe i can use local coordinates ins$$anonymous$$d of Vector3??

avatar image skovacs1 · Oct 21, 2010 at 07:31 PM 0
Share

The velocity Vector3(0,0,something) would indicate a movement along the world z axis by something. To get a local direction, you would either use crate.rigidbody.velocity = crate.TransformDirection(Vector3(0,0,something)); or you could just simply do crate.rigidbody.velocity = transform.forward * something; skovacs1 0 secs ago

avatar image John 17 · Oct 21, 2010 at 07:34 PM 0
Share

wow what a stupid mistake on my part. Thanks again!

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

No one has followed this question yet.

Related Questions

Why is velocity checking intensive? 0 Answers

How to move a rigidbody along a curve or spiral 0 Answers

Rigidbody Addforce cancels out Rigidbody velocity..maybe? 0 Answers

Add force on camera using AddForce 2 Answers

Can I use decreasing velocity to stop a hit ball overtime? 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