Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 kasazwix · Aug 08, 2015 at 11:54 AM · movementsphereballslowfix

The sphere goes Slow

Hi guys I'm an experienced programmer of unity 3d I have created a ball videogame , but when I try to move the ball the ball goes slow as a snail I also tried to increase the value of the (moveSpeed = to 60 or 100) but it does not work how i can solve this problem ?

 public class Ball : MonoBehaviour
 {
     public float moveSpeed = 50;
     public bool useTorque = true;
     public float maxAngularVelocity = 50;
     public float jumpPower = 2;
     public const float groundRayLength = 1f;
     private Rigidbody thisRigidbody;
     
     private Transform mainCamera;
     private Vector3 mainCameraForward;
     private bool jump;
     private bool superspeed;
     private Vector3 move;
     private Transform defaultParant;
     
     public GameObject messageText;
     //public Text coinsText;
     private int coinTotal;
     private int coinCount;
     public bool lastLevel;
     
     //public float newZCoordinate, newXCoordinate;
     public bool inAir = false;
     
     //instances
     private CheckpointManager chkMngr;
     
     
     private void Start()
     {
         Screen.lockCursor = true;
         Screen.showCursor = false;
         
         mainCamera = Camera.main.transform;
         thisRigidbody = GetComponent<Rigidbody>();
         GetComponent<Rigidbody>().maxAngularVelocity = maxAngularVelocity;
         
         coinTotal = GameObject.FindGameObjectsWithTag("Coin").Length;
         //coinsText.text = "Coins: " + coinCount.ToString() + "/" + coinTotal.ToString();
         defaultParant = transform.parent;
         chkMngr = GameObject.FindGameObjectWithTag("checkpointManager")
             .GetComponent<CheckpointManager>();
     }
     
     private void Update()
     {
         float h = Input.GetAxis("Horizontal");
         float v = Input.GetAxis("Vertical");
         jump = Input.GetButton("Jump");
         superspeed = Input.GetButton("Superspeed");
         
         if (mainCamera != null)
         {
             mainCameraForward = Vector3.Scale(mainCamera.forward, new Vector3(1, 0, 1)).normalized;
             move = (v * mainCameraForward + h * mainCamera.right).normalized;
         }
         else
         {
             move = (v * Vector3.forward + h * Vector3.right).normalized;
         }
         
         if (transform.position.y < -5)
         {
             ResetPosToLastCheckpoint();
             inAir = false;
         }
         
         if(inAir)
         {
             //Debug.Log ("IN AIR");
             
             if(Input.GetKeyDown(KeyCode.W))
             {
                 //float newZCoordinate = .02f;
                 //transform.position = Vector3.Lerp(transform.position,new Vector3(transform.position.x, transform.position.y, newZCoordinate),Time.fixedDeltaTime * 20);
             }
             if(Input.GetKeyDown(KeyCode.S))
             {
                 //float newZCoordinate = -.02f;
                 //transform.position = Vector3.Lerp(transform.position,new Vector3(transform.position.x, transform.position.y, newZCoordinate),Time.fixedDeltaTime * 20);
             }
             
             if(Input.GetKey(KeyCode.A))
             {
                 this.rigidbody.AddForce(new Vector3(0,0,.5f));
             }
             
             if(Input.GetKey(KeyCode.D))
             {
                 this.rigidbody.AddForce(new Vector3(0,0,-.5f));
             }
             
             
         }
         
         /*if (Input.GetKeyDown(KeyCode.Escape))
         {
            Application.LoadLevel("Menu");
         }*/
     }
     
     private void FixedUpdate()
     {
         
         if (useTorque)
         {
             thisRigidbody.AddTorque(new Vector3(move.z, 0, -move.x) * moveSpeed);
         }
         else
         {
             thisRigidbody.AddForce(move * moveSpeed);
         }
 
         if (Physics.Raycast(transform.position, -Vector3.up, groundRayLength) && superspeed)
         {
             thisRigidbody.AddForce(Camera.main.transform.forward * rigidbody.mass * 10, ForceMode.Impulse);
         }
         if (Physics.Raycast(transform.position, -Vector3.up, groundRayLength) && jump)
         {
             thisRigidbody.AddForce(Camera.main.transform.up * rigidbody.mass * 10, ForceMode.Impulse);
         }
         
         //thruster logic
         /*if (Input.GetKeyDown (KeyCode.T)) {
             rigidbody.AddForce(transform.forward * 2000f);
         }*/
     }
     
     void OnTriggerEnter(Collider _hit)
     {
         if (_hit.tag == "Coin")
         {
             Destroy(_hit.gameObject);
             coinCount++;
             //coinsText.text = "Coins: " + coinCount.ToString() + "/" + coinTotal.ToString();
         }
         else if (_hit.tag == "Next")
         {
             if (coinCount == coinTotal)
             {
                 if (lastLevel)
                 {
                     Application.LoadLevel("Menu");
                 }
                 else
                 {
                     Application.LoadLevel(Application.loadedLevel + 1);
                 }
             }
             else
             {
                 StartCoroutine(ShowMessage("You need to find all the coins"));
             }
         }
         else if (_hit.tag == "Platform")
         {
             Debug.Log("Allo m8");
             transform.parent = _hit.transform;
         }
     }
     void OnTriggerExit(Collider _hit)
     {
         if (_hit.tag == "Platform")
         {
             transform.parent = defaultParant;
         }
     }
     
     void OnCollisionEnter(Collision col)
     {
         if(col.gameObject.tag == "Platform")
         {
             inAir = false;
         }
     }
     
     IEnumerator ShowMessage(string _msg)
     {
         //messageText.SetActive(true);
         //messageText.transform.FindChild("Text").GetComponent<Text>().text = _msg;
         
         yield return new WaitForSeconds(2);
         // messageText.SetActive(false);
     }
     
     void ResetPosToLastCheckpoint()
     {
         //Grab last checkpoint location
         //Change position to last checkpoint position
         if(chkMngr.cache_check_points.Count == 0)
         {
             Application.LoadLevel(0);
             return;
         } else {
             Vector3 grabbedCheckpointPosition = chkMngr.cache_check_points[chkMngr.cache_check_points.Count - 1];
             Debug.Log (grabbedCheckpointPosition);
             transform.position = grabbedCheckpointPosition;
         }
         
     }
 }
Comment
Add comment · Show 2
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 Demonicdaron · Aug 08, 2015 at 11:58 AM 0
Share

Can you explain a bit better what the problem is? Like what are you expecting and what is the sphere actually doing and under what circumstance?

avatar image kasazwix · Aug 09, 2015 at 11:22 AM 0
Share

Hey guys how i can fix this problem ?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Aug 09, 2015 at 11:18 AM

You said you increased "moveSpeed". What exactly do you mean by that? Since it's a public variable it's serialized by unity, so when you want to change that value you have to change it in the inspector. Changing it in the code won't change anything.

If you already changed it in the inspector make sure you don't have a too large drag value on your rigidbody.

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 kasazwix · Aug 09, 2015 at 04:31 PM 0
Share

I tried everything of what I know , but the ball does not increase in the speed , then the drag It is set low

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Can a ball rotate without moving and changing its axis? 1 Answer

How to move a ball "faster" looking from a Camera 1 Answer

How can I create a sphere rotate in based on the direction it's moving? 1 Answer

Sphere + rigidbody + character controller 1 Answer

How can I cause a sphere to bounce forward infinitely with the same distance 3 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