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 devcor · Jul 05, 2014 at 07:55 PM · 2dphysicscollider3d

Physics - strange jumps.

Hello, guys! Here's the deal: I've got a 3d world with a 2d character in it (don't let the screenshots fool you, I've enabled 2d for better observation). There is a capsule collider on the character. Here's the code for it's controller:

 using UnityEngine;
 using System.Collections;
 
 public class JellyNew : MonoBehaviour {
     
     private GameObject child;
     public float maxSpeed = 5f; //Declare maximum speed
     bool facingRight = true;
     
     //Getting animator component from a child object
     public GameObject childWithAnimation; //Declaring input for editor
     Animator anim;
     void Awake () {
         anim = childWithAnimation.GetComponent<Animator> ();
     }
     
     //Ground Check
     bool onGround = false;
     public Transform groundCheck;
     float groundRadius = 0.2f;
     public LayerMask whatIsGround; //Declaring input for editor
     public float jumpForce = 700f; //Declare jumping force
     
     //bool doubleJump = false;
     
     // Use this for initialization
     void Start () 
     {
         child = GameObject.Find ("SpriteRotate"); //Finding a child which should be rotated
     }
     
     
     // Update is called once per frame
     void FixedUpdate () 
     {
         
         onGround = Physics.CheckSphere(groundCheck.position, groundRadius, whatIsGround);
         anim.SetBool("Ground", onGround);
 
         //if(onGround)
             //doubleJump = false;
         
         //How fast we're moving up or down
         anim.SetFloat("vSpeed", rigidbody.velocity.y);
         
         float move = Input.GetAxis ("Horizontal");
         
         anim.SetFloat ("Speed", Mathf.Abs(move)); //This is our current vertical speed
         
         rigidbody.velocity = new Vector2 (move * maxSpeed, rigidbody.velocity.y);
         
         if(move > 0 &&!facingRight)
             Flip();
         else if(move < 0 && facingRight)
             Flip();
     }
     
     void Update()
     {
         //If player on the ground and we're hitting 'Jump' button, we become no longer 'on the ground' and we're jumping
         if(onGround  && Input.GetButtonDown("Jump"))
         {
             anim.SetBool ("Ground", false);
             rigidbody.AddForce (new Vector2(0,jumpForce));
             
 
         }
     }
     
     void Flip() //This hideous, yet effective function rotates the child object with sprite and animation
     {
         facingRight =     !facingRight;
         Vector3 childScale = child.transform.localScale;
         childScale.x *= -1;
         child.transform.localScale = childScale;
     }
 }
 


When I stand on a step and jump, I jump just as I intend to - not too high up. That's the correct version. Here's a screen of a normal jump: alt text

THE PROBLEM: When I run towards the stairs and jump off of one step's edge, the character jumps enormously high. You can see how high he jumps on this screen: alt text

What's the problem with this all?

jumpnormal.jpg (72.3 kB)
jump2.jpg (63.2 kB)
Comment
Add comment · Show 4
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 Kiwasi · Jul 05, 2014 at 08:02 PM 0
Share

I suspect your grounded check is picking up the vertical edges of the stairs and 'regrounding' your character.

avatar image SepM · Jul 07, 2014 at 02:25 PM 0
Share

I'm having the same problem. I'll do a little searching around and see if I can get back to you!

avatar image meat5000 ♦ · Jul 07, 2014 at 02:52 PM 0
Share

Are you sure that's not the actual normal jump distance (given your jumpforce is 700) and that the jump you want is actually the result of the rigidbody and colliders dragging the distance down?

What happens if you jump away from the steps?

avatar image devcor · Jul 07, 2014 at 08:15 PM 0
Share

I guess no, that's not the normal jump. Because when I jump just standing on the floor or on the steps, he jumps a height of 2 grid squares, but when I jump running past the stair edges, he jumps 4+ squares. I'll make a video of that.

Btw, about 700 jumpforce - I adjusted it in the editor to 400 and the gravity is set to -15.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by drudiverse · Jul 07, 2014 at 04:22 PM

have a global variable that sais "LevelJumpedFrom"... and check the way you send cause effect to physics, the physics jump force musnt get anything else than level jumped from, and you should use rigidbody.velocity, its a read variable, unless you are doing something very core level in your physics... use addforce etc all the jump physics options.

dont use rigidbody.velocity to change things, it's read only

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 devcor · Jul 07, 2014 at 05:07 PM 0
Share

Thank you for your answer, but can you maybe describe more 'for stupid' style? I'm not any good with code yet, and I was doing this coding after a official live training tutorial.

avatar image
0

Answer by devcor · Jul 08, 2014 at 05:06 PM

So, guys, here's the video I've made. First few times I jump when the character isn't colliding with any steps at the moment of jumping. And as you can see he jumps almost to the top of the ladder.

But then I start running and jumping at the moment when he hits ladder collider, and you can see that he jumps much higher - he flies over the ladder.

http://www.youtube.com/watch?v=IrVmyqpddlY&feature=youtu.be

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

2D Collision not working! (child sprites colliders) 1 Answer

Retrieve 2d primitives from 3d colliders 1 Answer

Continuously moving rigidbody 2 Answers

Should 2.5D use 3D or 2D settings ? 3 Answers

Is it required to use 3D physics when a 2D game uses the z axis? 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