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 JeremyxLefebvre · Jul 02, 2021 at 10:21 AM · 2d-platformer2d-physicsplatformercoliderlayercollision

How to move a character in front of a collider and be able to jump and be on top of the said collider?

Hi,

I don't know if this has been answered here before but I would like to know how to move a character in front of a collider and be able to jump and be on top of the said collider. With the example below I want my character to move in front of the house but be able to

a) walk up the stairs

b) just jump on the balcony? Help?


182862-screen-shot-2021-07-01-at-120701-am.png


182860-screen-shot-2021-07-01-at-120733-am.png


screen-shot-2021-07-01-at-120701-am.png (122.4 kB)
screen-shot-2021-07-01-at-120733-am.png (68.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 Llama_w_2Ls · Jul 02, 2021 at 02:08 PM

One way you can do this is by setting the collider to IsTrigger, and setting it to a non-trigger collider if the player is on top of it. To detect whether the player is above the collider, use a raycast that points downward, and turn off IsTrigger for any colliders that it hits. For example:

 void Update()
 {
      ActivatePlatformGround();
 }
 
 void ActivatePlatformGround()
 {
      var hitInfo = Physics2D.Raycast(transform.position, Vector2.down);
      hitInfo.collider.isTrigger = false;
 }

@JeremyxLefebvre

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 Llama_w_2Ls · Jul 02, 2021 at 02:09 PM 0
Share

Note: All platforms in the scene need to be set back to IsTrigger if the player isn't above it. You can add a script to the platform to set itself to IsTrigger every LateUpdate or smt.

avatar image JeremyxLefebvre · Jul 03, 2021 at 01:12 AM 1
Share

Thank you!

I'm really new to all of this, program$$anonymous$$g with C# and Unity, as a whole, I am curious why write it in code versus using a PlatformEffector2d component?

avatar image Llama_w_2Ls JeremyxLefebvre · Jul 03, 2021 at 09:26 AM 0
Share

Yes, I originally wrote the question for a 3D and 2D solution, but for a 2D game like yours, a platform effector 2D works perfectly for this.

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

138 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

Related Questions

Character animation jerks when moving 1 Answer

Unity 2D player sticks on platform corners 2 Answers

Rigidbody2D.AddRelativeForce not working 1 Answer

2d Tilemaps, pass through some objects 1 Answer

[2Dplatformer][Problem] When the player closes to the enemy, the enemy pass through the colliders 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