Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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 /
avatar image
1
Question by Corbeau · Jan 16, 2014 at 07:49 PM · unity 2dphysics2dcollider 2dphysics 2d

2D Physics and Jump-Through Platforms

I need to set up jump-through platforms that will support characters landing on them from above but will allow them to jump through them from below. There was a fairly elegant solution in Unity Answers, but Physics2D for some unknown reason lacks the IgnoreCollision function. Is there another solution, aside from completely rebuilding all of my objects to use standard physics and colliders rather than the 2D versions?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by toxicFork · Jan 16, 2014 at 10:44 PM

Physics2D has IgnoreLayerCollision, which is not the best solution but it could work if you switch objects to different layers based on whether player is above or below the platform

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
avatar image
1
Wiki

Answer by locrian05 · Feb 22, 2014 at 12:39 PM

This is a simple script that I came up with, without using complicated scripting.

 //This script is attached to the player
         var jumpPower : float; //assign an integer for jump power
         var jumpKey : KeyCode; //assign jump button here
         var downKey : KeyCode; //assign down button here
         
         var box : BoxCollider2D; //assign the BoxCollider2D of your player and set it to is trigger
         
     function Update () 
     {
         //Jump
         if(Input.GetKeyDown(jumpKey))
         {
             rigidbody2D.velocity.y = jumpPower;
         }        
         
         // If you want your object to go down on your platform
         // Similar to the Contra game platform feature.
         if(Input.GetKeyDown(downKey))
         {
             box.isTrigger = true;
         }
     }        
 
 
         // have a seperated gameobject that has a boxcollider2d make sure is trigger is checked
         // in my case I named it Trigger and parent it to the platform
         // and make sure it is just a little under your platform.
         // your platform should have a boxcollider2D is trigger off
         
         // detects trigger and makes your players boxcollider2D isTrigger true which disables
         // collision and make it pass through your platform
         
         function OnTriggerEnter2D (hitInfo: Collider2D)
         {
             if(hitInfo.name == "Trigger") 
             {
                 box.isTrigger = true;
             }
         }
         
         
         // Exits your Trigger and set your player Collider2D.isTrigger false, which makes it collide
         // to your platform again.
         
         function OnTriggerExit2D (hitInfo: Collider2D)
         {
             if(hitInfo.name == "Trigger") 
             {
                 box.isTrigger = false;
             }
         }
 
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 Ash-Blue · Jul 13, 2014 at 02:14 AM 0
Share

While its a great idea, this will cause enemies or other players to fall through the platform too.

avatar image Lohoris2 · Sep 13, 2014 at 03:29 PM 0
Share

i.e. it's totally not a great idea at all.

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

20 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

Related Questions

Why does poligon collider 2d restricts movement of box collider? 0 Answers

AI phyics movement doesnt work 1 Answer

Making a bubble pop game type of shot trajectory 1 Answer

Unity 2D game: all colliders not working 3 Answers

Unity 2D: sprite's rigidbody weight/rotation 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