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 Reloaded23 · May 17, 2014 at 06:01 AM · velocityspeedforceprojectile

How to control the speed of the projectile motion?

I have created a simple script which will move the sphere in a projectile motion.

 public class ProjectileTest : MonoBehaviour 
 {
     public float power;
     public float speed = 1f;
     void OnGUI ()
     {
         if(GUI.Button(new Rect(100, 100, 100, 50), "Reset"))
         {
             Application.LoadLevel(Application.loadedLevel);
         }
     }
 
     void Update ()
     {
         if (Input.GetMouseButtonDown (0)) 
         {
 
         }
         if (Input.GetMouseButton (0)) 
         {
             power+=0.1f;
         }
         if (Input.GetMouseButtonUp (0)) 
         {
             Debug.Log("Power : "+power);
             if(power > 10)
                 power = 10f;
             transform.rigidbody.isKinematic = false;
             Vector3 forceVector = new Vector3(1, 1, 0);
         
             transform.rigidbody.velocity = forceVector * power * speed;
         }
     }
 }

Now as the question says, how can i control the speed of the projectile motion?

The sphere should move in the projectile but with a factor of speed.

Like sometimes i want it to move fast or slow but the projectile path should be same.

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 Kiwasi · May 21, 2014 at 09:58 AM 0
Share

You could play with the time scale

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by robertbu · May 17, 2014 at 06:17 AM

To change the speed, simply change the 'speed' or 'power' variable. But that does not get what you specify in the latter half of your statements. Having a projectile follow the path whether the projectile is fast or slow, breaks physics. The only way I can see with involve some somewhat complicated math and varying the gravity on a throw-by-throw basis. You could also abandon the use of the Rigidbody, and calculate the path directly and move the projectile using the Transform. A sine function makes a nice arc.

Comment
Add comment · Show 3 · 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 Reloaded23 · May 17, 2014 at 06:33 AM 0
Share

so with the current method i cannot control the speed of the projectile path?

avatar image Reloaded23 · May 21, 2014 at 05:54 AM 0
Share

Guys any other suggestion???

avatar image robertbu · May 21, 2014 at 03:54 PM 0
Share

so with the current method i cannot control the speed of the projectile path?

Not 100% true, but not easily solved either. The Rigidbody component uses the physics engine. This is an approximate simulation of real world physics. Imagine in the real world you were throwing a ball at some specified angle and it is hitting a target. If you slow down your throw the ball will fall short. If you speed up your throw, you will overshoot the target. There are a couple things that can be done. You can change the time scale as indicated by @Bored$$anonymous$$ormon, or you can change Physics.gravity, but I doubt either solution is one you are looking for.

If your criteria is a must, you will need to look to an alternate solution to a Rigidbody for your movement.

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

21 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

Related Questions

Im using add force to make a 'ship' go forward, if i release the key is there any way to slow it gradually? 1 Answer

Tank projectile speed 2 Answers

Increasing the speed of a ball in a brick breaker game 0 Answers

How do I give my ejected bullet shell a speed plus the player's current speed? 1 Answer

Firing projectile in curve 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