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 /
  • Help Room /
avatar image
0
Question by TARINunit9 · Feb 11, 2019 at 07:45 PM · collision2d game

*Temporarily* turn off collision between player and enemy

I'm trying to get into Unity's 2D development, so I downloaded the sample game project. The one with the bazooka and the London Bridge. One thing that really bugged me, the very first thing I wanted to change just to make the game PLAYABLE, is to make it so that the player can walk through enemies during "Mercy Invincibility". That is, the period of time after taking damage during which the player cannot take more damage. The way the game is currently set up, collision between player and enemy is always active and they always collide, but the player will simply not take damage under certain circumstances.

How would I set it up such that collision between player and enemy is disabled during a certain period of time, then automatically re-enabled afterward? Do I want to mess with Physics2DSettings menu? Do I want to call the Physics.IgnoreCollision() function? Do I want to add new variables to the player's global variables (like "public bool isTangible")? Am I overlooking something simpler?

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 xxmariofer · Feb 11, 2019 at 08:50 PM

hello, you can access the collider of the object using GetComponent() and set the enabled property to false. you can use a coroutine for that.

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 TARINunit9 · Feb 11, 2019 at 09:10 PM 0
Share

You've honestly lost me at "and set the enabled property to false". For one thing, it would never turn back to true even if I knew which Property of a Collider2D I was setting to false. It wouldn't quite fix what I'm trying to accomplish anyway. Effectively, now that I've revised my storyboard, I'm curious if it's possible to do something like this:

 PlayerHealth.cs
 void Awake
     {
         if (timer > 0) timer--;
         else open.Physics2DSettings -> Player/Enemy = true;
     }
 void OnCollisionEnter2D (Collision2D col)
     {
         TakeDamage (col.transform); 
         open.Physics2DSettings -> Player/Enemy = false;
         timer = 2f;
     }

using the Physics2DSettings menu. Is that possible, or is that going into protected regions of the engine?

avatar image xxmariofer TARINunit9 · Feb 11, 2019 at 09:26 PM 1
Share

you can do something like this

 Physics2D.IgnoreLayerCollision(1, 2, true);

you need to check whats the first and second collider layer index, just create 2 layers, one for theplayer and another for the enemy, and change the 1 and 2 of that line for the desired layer.

for setting it to collide again change the true for the false.

avatar image TARINunit9 xxmariofer · Feb 11, 2019 at 09:32 PM 0
Share

Perfect, thank you!

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

233 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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 check for colliders when teleporting the player in a 2D game? 0 Answers

I am new to unity and i am making a clone of a a game in which i have some problem 1 Answer

Layer Collision 0 Answers

Object reference not set to an instance of an object 0 Answers

How to move and rotate to other direction when hitting a wall 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