Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 andrewwebber25 · Jul 31, 2017 at 07:39 PM · jumpingplayer movementglitchgroundedborders

Player can jump on invisible non ground items

Alright everyone I think I got a tricky one for ya. So im making a 2D platformer where the player has a small collider attached to his feet called groundCheck. Its your basic ground check where if the player is not on the "ground", they cant keep jumping or walking. Everything seems to work fine except when I test it on my phone. In the game, if you jump to a platform and miss it, the player falls for a second and then hits an empty game object with a "Hazards" script attached to it. It the player tagged "Player" hits this collider, they spawn back to the beginning of the level to restart. Again, this works well when testing in unity but not quite when tested on the phone.

On the phone, if the player misses a platform and falls onto the hazard border, they will die (like they should) but if they keep pressing the jump icon, the player will jump one time and then when they hit the hazard border the second time, they will die. The jump button works fine in all other parts of the game, they can not continuously jump in the air or anything, its just when they are hitting the hazard colliders. Its puzzling because the border hazards have no affiliation with "ground" and should not allow the player to jump one or two times before dying! Plus its hard to test because like I said, it works fine on the computer but not the phone. Could it be my Jump touch button from my canvas? Sorry Im typing so much, I will upload anything you guys need me to. Thanks for the help!

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

Answer by bgprocks · Jul 31, 2017 at 07:59 PM

are you using coroutines at all, how are you processing the jump request. It sounds like you have an order of operations issue. Like your jump is getting processed before the collision code. one trick you can do is disable jumping as soon as the user is lower that the platform, or have a trigger object below the platform but above the hazard, once the player hit the trigger disable processing jump request.

Comment
Add comment · Show 2 · 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 andrewwebber25 · Jul 31, 2017 at 08:22 PM 0
Share

I think you may be on to something, its really the only thing I can think of that makes sense. Im going to put up some bits of code.

This is everything that has to do with jumping from my Touch code (this is the code for the jump button on the canvas that the player interacts with through the touch screen):

   public void Jump()
      {
          player.jump = true;
      }

This is all the jump related code attached to my Player:

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Scene$$anonymous$$anagement;

using UnityEngine.EventSystems; public class Player : $$anonymous$$onoBehaviour {

  public float maxSpeed = 3;
  public float speed = 50f;
  public float jumpPower = 150f;
  public bool jump;//this was added
  public float jumpheight;
  public bool grounded;

void Update() { anim.SetBool("Grounded", grounded); //This Jump code is to jump when space bar is pressed in unity if (Input.GetButtonDown("Jump") && grounded) { rb2d.AddForce(Vector2.up * jumpPower);

      }
 if ((jump) && grounded)//for jumping with the touch screen button
      {
          rb2d.velocity = new Vector2(rb2d.velocity.x, jumpheight);
          jump = false;
      }

} void FixedUpdate() { //Fake friction / Easing the x speed of our player if (grounded) { rb2d.velocity = easeVelocity; }

And possibly most importantly, this is my GroundCheck code:

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Scene$$anonymous$$anagement;

public class GroundCheck : $$anonymous$$onoBehaviour {

  private Player player;
 
  void Start()
  {
      player = gameObject.GetComponentInParent<Player>();
 
  }
 
  void OnTriggerEnter2D(Collider2D col)
  {
      player.grounded = true;
  }
 
  void OnTriggerStay2D(Collider2D col)
  {
      player.grounded = true;
 
  }
 
  void OnTriggerExit2D(Collider2D col)
  {
      player.grounded = false;
  }

}

Let me know if anything stands out! :)

avatar image bgprocks · Aug 01, 2017 at 01:17 AM 0
Share

Nothing is jumping out at me (not a pun) but will look it over again when I reboot my brain.

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

68 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

how to make bots stable? ,how to change bots movement? 0 Answers

Making a sphere jump on specific surfaces only 4 Answers

Player jump not working correctly 1 Answer

2D character can't jump off of platform floating in water 0 Answers

Auto Jump on 3d platform glitch 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