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 i_cant_draw · Nov 06, 2020 at 02:06 AM · unity 2d2d-platformercollision detectionlayerscollision2d

Collider Is Touching Layers is not working...

I know this is probably a simple answer, but I am very new to Unity and I can't seem to figure out what I'm doing wrong. I was following a 2D platformer tutorial series (https://www.youtube.com/watch?v=rMr1sHQ0_bc&list=PLpj8TZGNIBNy51EtRuyix-NYGmcfkNAuH) that showed a simple way to detect if the player is on the ground using this in a script:

 if (Input.GetButtonDown("Jump") && coll.IsTouchingLayers(ground))
         {
             Jump();
         }

This worked completely fine at the time. However, when I started a new project, I tried using the same way to do jumping, but the console shows errors, saying that there are errors with the next private void.

![Error][2] [2]: /storage/temp/170512-screen-shot-2020-11-05-at-85028-pm.png

My coding for the if statement is exactly the same, and I have a Jump function. I am able to jump if I don't input anything into the parentheses in the IsTouchingLayers. I have the exact same layer in the newer project, #8 being named ground. I looked and looked to see what differences there were between the projects but I could not find what was causing the problem. I'll provide the two different scripts below... Thank you to anyone who helps Tutorial and New Scripts

Edit: I just realized that the private void errors were caused by me forgetting a curly bracket, but it still does not work, as it says "The name 'ground' does not exist in the current context." Sorry for the error, again I am new.

tutorial-and-new-scritps.pdf (48.6 kB)
screen-shot-2020-11-05-at-85028-pm.png (64.2 kB)
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
Best Answer

Answer by swanne · Nov 06, 2020 at 08:35 AM

Hi,

The error message you are getting which explains that 'ground' does not exist in the current context leads me to believe that you have not declared a variable of type Layer, called ground.

Share your code here and I'll have a look

Comment
Add comment · Show 3 · 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 i_cant_draw · Nov 06, 2020 at 02:07 PM 1
Share

Thank you, I see the error in my code (I provided it in a pdf but for some reason, it wasn't showing up when I clicked the link... I had to open it in a new window and then download it...) I did not realize I needed a Layer$$anonymous$$ask variable named ground. I did this in the code that I had written down from the tutorial. If you don't $$anonymous$$d me asking - what exactly is a Layer$$anonymous$$ask? Why isn't the variable type just named Layer? What does the "mask" part mean? Thank you for your help even if this just felt like common sense to you!

avatar image swanne i_cant_draw · Nov 06, 2020 at 02:38 PM 0
Share

Hey @i_cant_draw

Great to hear that you've got it working now. A layer mask is used to help us make sense of the layer. Unity uses assigns bits to its layers - so it refers to them as 1,2,3,4,5 etc. To save us humans from having to remember which layer number 4 is, Unity uses Layer$$anonymous$$asks, which allows us to provide a readable textual description. So as an example, when we say check for layermask 'ground', unity translates that to 'layer 28'. Layer$$anonymous$$asks help us manage things easier.

avatar image i_cant_draw swanne · Nov 08, 2020 at 09:48 PM 0
Share

Sorry for the late reply, but thank you for explaining! Understanding what I'm doing really helps me to program better. I understand now, thank you so much!

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

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

Linecast Detecting Initial Collision Correctly, Need it to Stay Until Line Doesn't Intersect 1 Answer

Unity 2D - Game Collision Bug Error 0 Answers

How to change collision for just part of an object? (similar to sprite mask) 0 Answers

OnCollisionEnter2D is not working when an object tagged "Enemy" is not present in the game. 0 Answers

This question appears to everyone who has just started studying Unity, but I will ask again. How to prevent incorrect physics miscalculation and falling off the map in a 2D platformer? 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