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 mustafa · Sep 09, 2013 at 01:43 PM · physicsjumpfrictionphysxphysic

My Character is Jumping at different heights with physics for no reason

My Character is jumping at different heights and I just cant figure out why?

My Character jumps at a shorter height when he is standing right beside a cube. Why is this happing, i do not have friction on it, it shouldn't work this way.

The character have the following components attached:

  • Capsule Collider With Physic Material:

    *Dynamic Friction: 0; *Static Friction: 0; *Bounciness: 0; *Friction Combine: Minimum; *Bounce Combine: Minimum; *Firction Direction 2: (0, 0, 0); *Dynamic Friction 2: 0; *Static Friction 2: 0;

  • Rigidbody:

    *Mass: 1; *Drag: 0; *Angular Drag: 0.05; *Use Gravity: true; *Is Kinematic: false; *Interpolation: None; *Collision Detection: Discrete; *Freeze Position: (0, 0, 1); *Freeze Rotation: (1, 1, 1);

  • And a Script with the following code:


        using UnityEngine;
         using System.Collections;
         
         public class SimplePhysicsTest : MonoBehaviour {
             
             public float moveForce = 20;
             public float jumpForce = 300;
             
             [System.NonSerialized]
             public bool grounded = false;
             
             void FixedUpdate () {
                 // Get Inputs
                 float moveInput = Input.GetAxis("Horizontal");
                 bool jumpInput = Input.GetButtonDown("Jump") || Input.GetKeyDown(KeyCode.UpArrow);
                 
                 
                 // apply movement
                 if(moveInput != 0) {
                     rigidbody.AddForce(Vector3.right*moveForce*moveInput);
                 }
                 
                 // apply jumping
                 if(jumpInput && grounded) {
                     MDebug.Print("jump force: "+jumpForce+"N @ "+MUnity.SecondsToString((int)Time.time));
                     rigidbody.AddForce(Vector3.up*jumpForce);
                 }
                 
                 MDebug.md.debugText = "Grounded: "+grounded;
                 
             }
             
             
             
             // Checking if grounded
             void OnCollisionEnter(Collision collision) {
                 if(IsGroundCollision(collision)) {
                     grounded = true;
                 }
             }
             void OnCollisionStay(Collision collision) {
                 if(IsGroundCollision(collision)) {
                     grounded = true;
                 }
             }
             void OnCollisionExit(Collision collision) {
                 if(IsGroundCollision(collision)) {
                     grounded = false;
                 }
             }
             bool IsGroundCollision(Collision collision) {
                 Vector3 mostGroundedPoint = Vector3.zero;
                 foreach(ContactPoint cp in collision.contacts) {
                     if(cp.normal.y > mostGroundedPoint.y) {
                         mostGroundedPoint = cp.normal;
                     }
                 }
                 return (mostGroundedPoint.y >= 0.5f);
             }
     
     }
      
    
    

There is nothing else to it other then the mesh render and unrelated stuff

The tiles are the default Cubes in unity with a material on it and they are positioned perfectly from each other ie: cube1 (0,0,0), cube2 (1,0,0), ... etc

Can anyone tell me why he is not jumping the same height?

Note: (I don't own the art in the game, I'm using it only to learn and I'm not going to publish this game)

[1]: http://mudhishcode.com/test/platformer/Web.html

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

1 Reply

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

Answer by eddyzy · Sep 09, 2013 at 02:11 PM

i don`t know but the movement is jumpy because you move by adding force to your rigidbody.

Why dont you use transform.Translate();?

and to achieve the slowing down effect you could use Matf.SmoothDamp();

http://docs.unity3d.com/Documentation/ScriptReference/Mathf.SmoothDamp.html http://docs.unity3d.com/Documentation/ScriptReference/Transform.Translate.html

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 mustafa · Sep 10, 2013 at 08:58 AM 0
Share

Thanks, but if I use transform.Translate() with rigidbody on I get wired effects and I want my character to have physics interactions. I've solve it with setting rigidbody.velocity. It work well :)

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

16 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

Related Questions

Physics engine with double precision 0 Answers

Angular Friction 0 Answers

Calculating Sphere vs. Plane Friction 1 Answer

How to make moving objects stack, without sliding over each other? 0 Answers

Calculating required force for pushing a body to a desired position at once 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