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 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.

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

Imported model is rotated 90 degrees off of straight, can't use any transforms 1 Answer

Reading force on rigidbody? 1 Answer

To Clarify On the Unity's Unit of Force 3 Answers

How to get the direction of the velocity of an object (c#) 1 Answer

Inhibit force from doubling when 2 axes are active 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