• 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 NicolusBuck · Jan 12, 2016 at 09:32 PM · c#physicsrigidbodyaddforceplayer movement

Ball Speed is not increasing as per code

I am working on small project , but now I have a problem . The problem is The Player speed (Ball speed) is not increasing as per the code .

In the beginning ball speed increases , but as the time goes the speed becomes constant .

I made Gravity as -50 in Y - Axis .

So here is the C# Script attached to the ball :-

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class Ball_Script : MonoBehaviour 
 {
     // Ball Physics Variables
     private Rigidbody Ball_Rigid;
     public float Ball_Speed = 10f;
     private float Speed_Change_Time = 1.0f ;
 
     // UI Text
     public Text My_Ball_Speed_Text ;
     public Text My_Key ;
 
     // Use this for initialization
     void Start () 
     {
         Ball_Rigid = GetComponent<Rigidbody>();
         My_Ball_Speed_Text.text = Ball_Speed.ToString () + " km/h";
         My_Key.text = "No Key Pressed";
     }
     
     // Update is called once per frame
     void Update () 
     {
         // Restart game
         if(transform.position.y < -7.0f)
         {
             Application.LoadLevel(0);
         }
         
         // Ball Automatic Movement script Starts here
         Speed_Change_Time_Interval ();
         Ball_Rigid.AddForce (new Vector3 (Ball_Speed * -1 * Time.deltaTime, 0, 0));
         // Ball Automatic Movement script Ends here
         
         if(Input.GetKeyDown(KeyCode.LeftArrow))
         {
             Ball_Rigid.MovePosition(new Vector3(transform.position.x , transform.position.y , transform.position.z - 1.0f));
             My_Key.text = "Left Arrow Pressed";
         }
         
         if(Input.GetKeyDown(KeyCode.RightArrow))
         {
             Ball_Rigid.MovePosition(new Vector3(transform.position.x , transform.position.y , transform.position.z + 1.0f));
             My_Key.text = "Right Arrow Pressed";
         }
     }
 
     // This Fixed update stops the ball from bouncing
     void FixedUpdate()
     {
 
         Vector3 currentVelocity = Ball_Rigid.velocity;
         
         if (currentVelocity.y <= 0f) 
             return;
         
         currentVelocity.y = 0f;
         
         Ball_Rigid.velocity = currentVelocity;
     }
 
 
     // This function increases the ball speed in every 1 second 
     void Speed_Change_Time_Interval ()
     {
         Speed_Change_Time = Speed_Change_Time - Time.deltaTime;
         
         if(Speed_Change_Time <= 0)
         {
             Ball_Speed = Ball_Speed + 10;
             Speed_Change_Time = 1.0f;
             print(Ball_Speed);
             My_Ball_Speed_Text.text = Ball_Speed.ToString ()+ " km/h";
         }
     }
 }
 


Here FixedUpdate () stops the ball from bouncing and Speed_Change_Time_Interval () function increases the ball speed in every second . But it works some extent . Then there is no change in speed of the ball . Here is the video of the game ( Recorded with Jing, so file is in .swf format . Sorry for that :( )Link :- http://www.mediafire.com/download/ibk4ffjm3y6i96y/Ball_Vid.swf

File size = 9.28 MB

So what is the problem of this script . If my method is wrong / not good please suggest me a good one :).

Hope you will help me to figure it out .

Thanks , Regards

NB :)

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

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Script makes plane point in general direction but doesn't point fully... read description please! 1 Answer

How to make Airplane move forward faster INSTANTANEOUSLY? 1 Answer

Player Movement Goes Crazy When Hit On Side Of Moving Platform 0 Answers

AddForce and Momentum‏ 1 Answer

Rigidbody falling not according to physics, only when script is applied. 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