• 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 ragozh · Aug 03, 2020 at 08:27 PM · forcethrowing

How to speed up projectile thrown?

I'm trying to throw a dagger by adding force base on vector drawn by holding mouse. Everything worked fine, only problem is the dagger took too long time to fly, even a short distance with small force took about 4, 5 seconds. Is there any solution for this or am I doing something wrong? Here's the code:

     void Update()
         {
             // Get mouse positiom
             Vector3 mousePos = Input.mousePosition;
             mousePos.z = 200;
             Vector3 mouseWorldPos = Camera.main.WorldToScreenPoint(mousePos);
     
             if(Input.GetMouseButtonDown(0) && ProjectileLauched == false){
                 IsAiming = true;
                 // Check if this position is the beginning of drag
                 if(beginDrag == false){
                     startPos = mouseWorldPos;
                     beginDrag = true;
                 }
             } else if(Input.GetMouseButtonUp(0) && IsAiming && ProjectileLauched == false){
                 endPos = mouseWorldPos;
                 beginDrag = false;
                 if(checkValidDrag()){
                     IsAiming = false;
                     ProjectileLauched = true;
                     Vector3 forceDrawn = endPos - startPos;
                     forceDrawn.z = mousePos.z;
                     Debug.Log(forceDrawn);
                     ActiveWeapon.GetComponent<Rigidbody>().useGravity = true;
                     ActiveWeapon.GetComponent<Rigidbody>().AddForce(forceDrawn * 0.7f, ForceMode.Impulse);
                 }
             }
             // Rotation on hold
             if(beginDrag == true){  
                 Vector3 vectorDrawn = mouseWorldPos - startPos;
                 Quaternion rotation = Quaternion.LookRotation(vectorDrawn, Vector3.forward);
                 ActiveWeapon.transform.rotation = rotation;
             }
         }

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 CodesCove · Aug 03, 2020 at 10:38 PM

I don't know if this helps but here are few thing that that can affect the speed

  • Rigidody Mass value. Higher mass value causes slower speed in the initial impulse and vice versa (notice that mass!=weight).

  • Rigidody Drag. Higher value then the objects speed decelerates faster and vice versa

  • Rigidody Any active Constraints that might prevent movement

  • Magnitude of .AddForce force vector. The larger the magnitude the higher the initial speed is

  • Direction of the .AddForce force vector especially if the useGravity is enabled. If you shoot against the Physics gravity vector then the speed is decelerated until object comes down (you can set it in the Edit -> Project Settings -> Physics --> Gravity)

  • Time.timeScale value that is affects all the motion. If lower than 1 then the motion (and almost whole game except frame rate depended parts) is slowed down.


This might be something that is done intentionally but just make sure.. In your code you take the direction but then set the direction vectors z-value to mousePos.z = 200. That value is included to both the direction and to the magnitude of the force vector that is applied to the projectile. If you want pure direction then you get from forceDrawn.normalized property and then multiply that with force value to get the real force vector (that includes direction and force). Hope you get it working!

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 ragozh · Dec 06, 2020 at 08:34 PM 0
Share

I just realize I scaled my objects too big so when I throw, it's like lauching a rocket in thousand kilometers.

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

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

Related Questions

Apply force at an angle or transform.rotation 1 Answer

Melee attacking, using force and health values 1 Answer

stop adding force 2 Answers

How can I apply force in the direction of the camera when the user presses the mouse 1 Answer

Force iOS first person to move slightly when player is not moving it? 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