Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 N1warhead · Oct 06, 2014 at 02:44 PM · updatejumpingfixedupdateinterpolation

Interpolation with jumping - Acting Weird.

Here is my player controller I have been working on.

Everything works fine, finally found out that using Interpolation for jumping smoothed out the jitteryness of jumping, which thankfully I found.

But now I am running into a stump in the road.

I can still jump fine when I stand still, however, if I start moving, I jump maybe not even half way as high. I tried using Extrapolate or whatever, it was worse than not having Interpolate, but here is my code.

     //private CapsuleCollider col; // This is the Collider for Player.
     private Animator anim;    // This is the Animator for Player.
     public float Speed = 5.0f;
     public float TurnSpeed = 5.0f;
     public float jumpHeight = 10.0f;
     public bool canJump;
     public bool Transition = false;
     // Use this for initialization
     void Start () {
     anim = gameObject.GetComponent<Animator>();
     }
     
     // Update is called once per frame
     void Update () {
 
                 if (!Transition) {
                         if (Input.GetKey (KeyCode.W)) {
                                 transform.Translate (Vector3.forward * Speed * Time.deltaTime);
                                 anim.SetFloat ("Speed", 1f);
                         } else {
                                 anim.SetFloat ("Speed", 0f);
                         }
                         if (Input.GetKey (KeyCode.S)) {
                                 transform.Translate (Vector3.back * Speed * Time.deltaTime);
                                 anim.SetFloat ("WalkBack", -1f);
                         } else {
                                 anim.SetFloat ("WalkBack", 0f);
                         }
                         if (Input.GetKey (KeyCode.A)) {
                                 transform.Rotate (0,-3,0 * Time.deltaTime);
             }
                         if (Input.GetKey (KeyCode.D)) {
                                 transform.Rotate (0,3,0 * Time.deltaTime);
                         }
 
                 }
     }
     
     
     void FixedUpdate(){
     
     if (Input.GetKeyDown (KeyCode.Space) && canJump == true) {
                         if (canJump) {
                 anim.SetBool ("Jump", true);
                 transform.rigidbody.AddRelativeForce (Vector3.up * jumpHeight);
                 Physics.gravity = new Vector3 (0, -20, 0);
             }
     }
   }
     void OnCollisionEnter(Collision col){
         if (col.gameObject.tag == "Map") {
             anim.SetBool ("Jump", false);
         }
     }
 }
 

Please, if you can help me, all would be greatly appreciated!

Comment
Add comment · Show 6
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 N1warhead · Oct 07, 2014 at 06:29 AM 0
Share

I'm not trying to bump this, but I really need some kind of help with this, please...

To be honest I'd rather not even use forces for jumping, I don't see why a transform.Translate (Vector3.Up 10 Time.deltaTime); won't work.

But now I have the jumping working with forces, but now, no matter what I do, my turning is all weird.

I put physics materials on ground, I drag the Drag and $$anonymous$$ass up and now I'm getting the most akward kind of turns.

But I don't get WHY I can't just use the Jumping force with my normal transform.Translate.. The result = I can jump fine when standing still, but when I move, the force is cut in half, but when i have forces doing my movement, the jumping force is fine, but then a transform.Rotate doesn't turn my player currectly as the Forward pushing force is trying to slide me, no matter what settings I have changed.

This is getting on my last nerve. Please help me guys!

avatar image Dave29483 · Oct 07, 2014 at 07:15 AM 0
Share

Could be wrong but seems like you're doubling gravity in your jump function. logically you would need twice the jump force?

avatar image Dave29483 · Oct 07, 2014 at 07:18 AM 0
Share

As for sliding, you need your damping on the rigid body roughly 10x your movement force. $$anonymous$$g. A linear movement force of 1 with a damping of 10 give you a sharp but smooth deceleration like the old mario games.

avatar image N1warhead · Oct 07, 2014 at 07:23 AM 0
Share

Yeah i was doing gravity like that as it kept my player to the right height that I wanted, if I took it off, he would just slowly fall to the ground, like really slow. Figured it would be better to do it that way than doing it in Unity, as I may not want anything else to fall that fast as it's supposed to be ("real") life gravity already set up isn't it?

I'll try the damping and stuff, damping is the Drag right?

Right now all I know is, when it turn, it's like a Dirt Bike turning, the bottom of the player appears to be like hitting a "Rut" because the forward direction of (force) still slightly pushes as I am rotating.

avatar image Dave29483 · Oct 07, 2014 at 07:31 AM 0
Share

Yea drag is the right one. It should fix that for you. In my experience 10x the input force gives a rapid deceleration, but doesn't take so long it looks like you're on ice. If you want to stop quicker just ramp up the drag further.

As for gravity, turn it off on that rigid body and apply it yourself. In most games a gravity of -20 to -30 for jumping looks pleasing. This way you can have it only affect that object.

Show more comments

1 Reply

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

Answer by unimechanic · Oct 08, 2014 at 02:08 PM

There are three very common pitfalls when using physics in Unity 4.x and lower (that use Nvidia PhysX 2):

  • Altering static colliders.

  • Altering a GameObject that has a Rigidbody without using the Rigidbody members.

  • Altering a Rigidbody outside of FixedUpdate.

Altering means: enabling (i.e. SetActive) or transforming (moving, rotating, scaling). So, whenever there is a GameObject with a Rigidbody, it must always be transformed with the corresponding Rigidbody's members, and always inside FixedUpdate. I see you are using both Update & FixedUpdate, and Transform & Rigidbody operations.

Make sure of the following:

  • If the collider is loaded/unloaded along with the scene and shouldn't be altered in any way, it can be a static collider.

  • If the collider is created/destroyed dynamically or is modified in some way, it must be a dynamic collider.

More on static colliders here:

http://docs.unity3d.com/430/Documentation/Components/DynamicsGroupOverview.html

Doing otherwise will corrupt the physics scene and physics operations could fail, until it's reconstructed, which is expensive and will happen at some unknown point. This is an indirect and accumulative effect that developers might not notice, and if they do, they will have difficulties to understand the cause.

This will be improved in Unity 5, with Nvidia PhysX 3:

http://blogs.unity3d.com/2014/07/08/high-performance-physics-in-unity-5/

Comment
Add comment · 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

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

30 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

Related Questions

InvokeRepeating OR Update OR FIxedUpdate? 2 Answers

Jumping randomly doesn't work 2 Answers

Updating at frameRate some fixedUpdated gameObject 1 Answer

How do I fix jitter? 1 Answer

Could Update and FixedUpdate happen at the same time? 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