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 itsboshytime · Feb 25, 2014 at 08:57 PM · c#physicsjumpforcetimescale

Jumping through the roof!

Hello,

I've made the follwing jump code. Time is frozen and the character is stuck mid air. When you click on the screen force is applied so he jumps for a bit.

But once every 10-15 times, he goes through the roof when i first click the screen. I have no idea why this is happening or how to fix it. i've tried a lot of different things but since i have no idea what the problem is i cannot fix it. Help would be appreciated.

You can see for yourselves in a version i made for kongregate ( press space to jump)

http://www.kongregate.com/games/axell/bouncy-ninja

 using UnityEngine;
 using System.Collections;
 
 [System.Serializable]
 public class JumpNinja : MonoBehaviour {
 
 
     // The fx,fy,fz - forces in x/y/z direction. by default, fz = 0 
 
     public float fx;
     public float fy;
     public float fz;
     public GUIText tapText;
 
     void Awake(){
         Time.timeScale=0;
         Debug.Log("timescale");
         //rigidbody.AddForce(fx,fy,0);
         }
 
     void Start () {
         rigidbody.AddForce(fx,fy,0);
     }
     
     void Update(){
     
         if (Input.GetMouseButtonDown(0))
         {
             Debug.Log("Working");
             if (Time.timeScale == 0)
             {    
                 tapText.guiText.enabled = false;
                 Time.timeScale=1;
             }
             audio.Play();
             rigidbody.AddForce(0,fy,0);
             rigidbody.velocity = new Vector3(rigidbody.velocity.x, 0, rigidbody.velocity.z);
             //rigidbody.AddForce(0,fy,0);
         }
     }
 
 }
Comment
Add comment · Show 5
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 Dimwood2011 · Feb 25, 2014 at 09:20 PM 0
Share

does it help if u try FixedUpdate?

avatar image rockyourteeth · Feb 25, 2014 at 09:55 PM 0
Share

No advice, but fun game. :)

avatar image itsboshytime · Feb 25, 2014 at 10:24 PM 0
Share

@Dimwood I did try fixedupdate. It still happens :( @Rockyourteeth Thanks! The android version is even better

avatar image itsboshytime · Mar 02, 2014 at 06:22 PM 0
Share

Nobody has any solution to this?

avatar image itsboshytime · Mar 07, 2014 at 08:14 PM 0
Share

Bump for this? It's really critical and i have no idea why it happens.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by rockyourteeth · Mar 07, 2014 at 09:32 PM

Just a guess, but could it be that you're using "AddForce" both in the Start and the Update functions? Might this cause the character to get double the force on its first step?

Sorry, I played the game over and over to try to find a repeatable pattern, but it does seem to happen at random.

EDIT: This wasn't the problem (see comments below). The problem turned out to be that:

There's some weird behavior when time.timescale is set in the Awake() or Start() functions. Try putting it in the Update() function, and make it so it only runs the first time.

Comment
Add comment · Show 4 · 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 itsboshytime · Mar 08, 2014 at 09:23 AM 0
Share

I've tried abunch of different solutions, but to no avail. But i did discover something interesting. I can reproduce it 100% now if i do it like this

if (Time.timeScale == 0) {
tapText.guiText.enabled = false; Time.timeScale=1; rigidbody.AddForce(fx,fy,0); }

ins$$anonymous$$d of putting it in the start. Now that is strange.

avatar image rockyourteeth · Mar 08, 2014 at 03:08 PM 0
Share

According to this thread, it looks like there's some weird behavior when time.timescale is set in the Awake() or Start() functions. Try putting it in the Update() function, and make it so it only runs the first time.

avatar image itsboshytime · Mar 08, 2014 at 06:00 PM 1
Share

Thanks for the answer. Putting the TimeScale in FIxedUpdate did the trick.

avatar image rockyourteeth · Mar 09, 2014 at 05:34 AM 0
Share

Great! Glad I could help! I added that to my answer, so please label that as the correct answer if it indeed fixed it.

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

22 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

Related Questions

Adding double jump to physics platformer kit? 2 Answers

Interpolate problem? Jump isn't smooth... 1 Answer

Jump animation won't move forwards 1 Answer

How can I make a physics object jump a given height on collision regardless of current velocity? 1 Answer

Set Velocity at relative position. 2 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