Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Suppapa · Oct 07, 2015 at 08:15 AM · scripting problemaddforcescriptingbasics

AddForce Isn't working?

I have tried looking this question up but it doesn't come up with an answer to my problem so I have some code that should say on start the object has a force applied to it but it doesn't work? and yes I do have a rigidbody on it

Code:

 using UnityEngine;
 using System.Collections;

 public class HarpoonSharp : MonoBehaviour {
 public float power = 10;
 public Vector3 shot;
 public Rigidbody rb;
 void Awake () {
     transform.Rotate(Vector3.right, 90);
 }

 void Start () {
     rb = GetComponent<Rigidbody>();
     rb.AddForce(shot * power);

 }

 void Update () {

 }



 }

I have to rotate it right because of how the model was imported and I have tried disabling that part and it still does not work

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

1 Reply

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

Answer by HarshadK · Oct 07, 2015 at 08:20 AM

There is no default value assigned to your shot variable which means it will be Vector3.zero by default, which you need to set to some value by either assigning a default value in code or you can even set value from editor since in your Start method you are using shot * power which will be zero since your shot is zero. Also AddForce will apply force just for one frame in your Start method, so you have to add enough force to make that object move in that frame by adjusting the value of your power variable or adding a force of type ForceMode.Impulse.

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 Suppapa · Oct 09, 2015 at 03:14 AM 0
Share

By any chance do you know how to make a vector 3 a local variable? like based on where I am looking?

avatar image HarshadK · Oct 09, 2015 at 05:43 AM 0
Share

I think Transform.forward is what you are looking for.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

need some help with scripting 1 Answer

Performance peaks in ScriptRunBehaviourUpdate 1 Answer

How to make AddForce dash smoother, instead of teleporting 1 Answer

Variable from another script isn´t updating 3 Answers

Performance of event vs static method call 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