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 · Aug 15, 2017 at 08:45 PM · movementjumpingtouch controlsgroundedground detection

Player can jump on non ground hazards?

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. If the player tagged "Player" hits this collider, they activate the Is Trigger and spawn 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 can actually keep jumping. 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! Its like the order of operation is messed up or something. I wanted to create a second invisible collider just above the first "Hazard" one that will stop the player from using the jump command. Any help on how I can do this? Here's what I got so far, thanks everyone!`

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;

 public class NoJump : MonoBehaviour
 {

 public Rigidbody2D rb;
 private ObjectMove player;
 public bool jump;
 public float jumpheight;
 private bool onGround;



 void Start()
 {
     player = FindObjectOfType<ObjectMove>();
 }

 void Update()
 {
     if (jump)
     {
         if (onGround)
         {
             rb.velocity = new Vector2(rb.velocity.x, jumpheight);
         }
         jump = false;
     }
 }

 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.tag == "Player")
     {
         jump = false; 
     }
 }

}`

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
0

Answer by SponOriginal · Aug 15, 2017 at 09:11 PM

When player jumps on the hazard zone, you can make the "hazard zone" disable the jumping script so player wouldn't be able to jump, I think it would be easier than putting everything in one script. For example :

void OnTriggerEnter2D(colider2D other) { GetComponent( *name of your jumping script*).enabled = false; }

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 andrewwebber25 · Aug 18, 2017 at 01:17 PM 0
Share

Okay that sounds awesome, can you help me add it, I keep getting compiler errors. Im trying to add that to my "Hazard" Script which is what is attached to my enemies. This is the code I currently have that kills the player OnTrigger. $$anonymous$$y jumping script is called "Touch".

 void OnTriggerEnter2D(Collider2D other)
     {
         if (other.tag == "Player")
         {
             player.transform.position = start.position;
         }
     }

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

98 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 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

Player can jump on non ground items 1 Answer

Grounded check not working on sloped ground. 1 Answer

How to only Jump on Ground Items 1 Answer

How to jump on only "ground" colliders 1 Answer

Player does not jump when running at the edge of a ledge (How to add jump tolerance?),Player Does not jump when at the edge of a ledge 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