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 superluigi · Aug 24, 2013 at 09:28 PM · rigidbodyaddforce

Help with addforce

Arrow instantiates but doesn't have any force added so it just drops straight down.

 var shooter : Transform;
 var arrow : Rigidbody;
    
 function Start () 
 {
     shooter = GameObject.Find("shooter").transform;
 }
 
 function Update () 
 {
     if (Input.GetKeyDown("y"))
     {
         Instantiate(arrow, shooter.position, shooter.rotation);
         arrow.rigidbody.AddForce(Vector3.forward * 1000);
         arrow.transform.forward = Vector3.Slerp(arrow.transform.forward, arrow.rigidbody.velocity.normalized, Time.deltaTime);        
     }    
 }
Comment
Add comment · Show 9
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 gamerant · Aug 24, 2013 at 09:33 PM 0
Share

Have you tried attaching a rigid body to your arrow and then unticking the gravity check box?

avatar image superluigi · Aug 24, 2013 at 09:37 PM 0
Share

Not sure what you mean by not accessing rigidbody through script

avatar image gamerant · Aug 24, 2013 at 09:44 PM 0
Share

Well you can either add a rigidbody in the inspector to your game object or you can add it through script(accessing here.Sorry for the terrible choice of words).

avatar image superluigi · Aug 24, 2013 at 09:50 PM 0
Share

Yea it already had a rigidbody attached through the inspector

avatar image superluigi · Aug 24, 2013 at 09:57 PM 0
Share

Yea I think what I need to do is make the instantiated object its own variable and it'll work. Also does .rigidbody mean that its attaching a rigidbody to the object? I thought it meant this objects rigidbody.

Show more comments

1 Reply

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

Answer by getyour411 · Aug 24, 2013 at 09:54 PM

Not sure what shooter and such is in your game, but I copied this into a test project and it fires straight ahead

 var shooter : Transform;
 var arrow : GameObject;
 var thisArrow : GameObject;
  
 function Start ()
 {
 shooter = GameObject.Find("shooter").transform;
 }
  
 function Update ()
 {
 if (Input.GetKeyDown("y"))
 {
 
 thisArrow = Instantiate(arrow, shooter.position, shooter.rotation) ;
 
 thisArrow.rigidbody.AddForce(Vector3.forward * 1000);
 thisArrow.transform.forward = Vector3.Slerp(thisArrow.transform.forward, thisArrow.rigidbody.velocity.normalized, Time.deltaTime);
 }
 }

I had shooter as a child to the FPController object, but that doesn't rotate with the parent so it only fires forward. See if you can adapt that to your setup. Also make note of the remark about using AddForce in Update v FixedUpdate @ http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.AddForce.html

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 superluigi · Aug 24, 2013 at 10:18 PM 0
Share

thisArrow.Addforce(transform.forward * 1000) this will make it shoot forward in the direction. In your example you would need the .rigidbody before .Addfoce

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

18 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

Related Questions

Rigidbody.AddForce strange with L/R movement? 1 Answer

How to fire a gun using raycasting and still add force 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Player isn't moving (AddForce) (Hook)(c#) 1 Answer

If You add a RelativeForce to an Object like a Sphere, Does Speed ever decrease and stop? 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