Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Filipposan · Oct 25, 2015 at 03:17 AM · collision2d-platformercollision detectioncollider2dignore collisions

Jump off 2D platforms Smash brothers style.

i have been using

 void OnCollisionStay2D(Collision2D other) {
 
         if (Input.GetKeyDown(KeyCode.DownArrow ) == true)
         {
  platform.transform.GetComponent<BoxCollider2D>().enabled = false; //<--- this one works.



    Physics2D.IgnoreCollision(other.transform.GetComponent<CircleCollider2D>(), platform.transform.GetComponent<BoxCollider2D>()); //doesnt work
    Physics2D.IgnoreCollision(other.transform.GetComponent<BoxCollider2D>(), platform.transform.GetComponent<BoxCollider2D>()); //doesnt work
         }
 
     }

but it simply doesnt work, now if i deactivate the box collider i cant simply turn it back on with an oncollisionexit2d function since it wont know when the collision ended.

the platform parents the other objects it carries with a 1 scale parent to avoid graphical errors.

what would you use ?

Comment
Add comment · Show 2
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 Filipposan · Oct 25, 2015 at 03:41 AM 0
Share

pass through the platform if down key is pressed while on it.

avatar image Ymrasu · Oct 25, 2015 at 06:16 AM 1
Share

Is the OnCollisionStay2D() on your player or your platform script?

if it is on your player you can use:

 void OnCollisionStay2D(Collision2D other)
 {
     if (other.tag == "Platform")
     {
         if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.DownArrow))
         {
             Physics2D.IgnoreCollision(other.GetComponent<Collider2D>(), GetComponent<Collider2D>());
         }
     }
 
 }

you would need to make a tag of "Platform" and change the tag of the platform to that

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Filipposan · Oct 28, 2015 at 06:04 AM

OK, thank you very much for your Answer, it helped me develop this :

Here's the whole class:

 public class PassThrough : MonoBehaviour {
 
     public bool checkcol;
     public Collider2D lastPlatform;
     public string lastPlatformName;
 
     // Use this for initialization
     void Start () {
         checkcol = false;
     }
     
     // Update is called once per frame
     void Update () {}
 
     void OnCollisionEnter2D(Collision2D other) {
 
         if (other.transform.name != lastPlatformName) {
 
          
             Physics2D.IgnoreCollision(lastPlatform, GetComponent<BoxCollider2D>(),false);
             Physics2D.IgnoreCollision(lastPlatform, GetComponent<Collider2D>(),false);
 
         }
 
     }
 
 
 
     void OnCollisionStay2D(Collision2D other) {
          if (other.transform.tag=="MovingPlatform")
                 if (Input.GetKeyDown(KeyCode.DownArrow))
                 {
                 lastPlatformName = other.transform.name;
                 lastPlatform = other.transform.GetComponent<Collider2D>();
                     Physics2D.IgnoreCollision(lastPlatform, GetComponent<BoxCollider2D>());
                     Physics2D.IgnoreCollision(lastPlatform, GetComponent<Collider2D>());
                 }

}

     }


this class lets my character with 2 hit boxes pass through moving platforms, and re enter them if you touch anything else which will most likely be the case.

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

36 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

Related Questions

OnTriggerEnter not being called 2 Answers

Player passenger moving when being pushed by two platforms 0 Answers

Enemies spawning on top of each other,Enemies spawn on top of each other 0 Answers

2D colliders doesnt work with Gravity Scale = 0 0 Answers

Unity 2D does not detect collisions 0 Answers


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